#include <iostream>
#include <queue>
using namespace std;
struct node{
int kovetkezo, bejart=-1, x=0, loop=0;
};
node a[200000];
int n, y;
int hossz(int& x, int& l){
//cout << x << ' ';
if(a[a[x].kovetkezo].loop!=0){
a[x].loop=l;
return l;
}
else{
a[a[x].kovetkezo].loop=hossz(a[x].kovetkezo, l+1);
return a[a[x].kovetkezo].loop;
}
}
void loopcheck(int& x){
a[x].loop=1;
hossz(x, 1);
}
int dfs(int& h){
//cout << '"' << h << '"';
int l=0;
int x=h;
while(a[x].bejart!=h){
if(a[x].loop){
l+=a[x].loop;
break;
}
else{
a[x].bejart=h;
x=a[x].kovetkezo;
l++;
}
//cout << x << ' ' << a[x].kovetkezo << '\n';
}
if(a[x].loop==0){
loopcheck(x);
}
return l;
}
int main()
{
int maxi=-1, maxind;
cin >> n;
for(int i=0; i<n; i++){
cin >> a[i].kovetkezo;
a[i].kovetkezo--;
a[a[i].kovetkezo].x++;
}
bool d=1;
for(int i=0; i<n; i++){
//cout << i+1 << ": " << a[i].x << '\n';
if(a[i].x==0){
d=0;
int t=dfs(i);
if(t>maxi){
maxi=t;
maxind=i+1;
}
}
}
if(d){
for(int i=0; i<n; i++){
if(a[i].bejart==-1){
int t=dfs(i);
if(t>maxi){
maxi=t;
maxind=i+1;
}
}
}
}
/*for(int i=0; i<n; i++){
cout << a[i].loop << ' ';
}*/
cout << maxind << ' ' << maxi << '\n';
return 0;
}
open /var/local/lib/isolate/440/box/a.out: no such file or directory
main.cpp: In function 'int hossz(int&, int&)':
main.cpp:19:55: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
19 | a[a[x].kovetkezo].loop=hossz(a[x].kovetkezo, l+1);
| ~^~
main.cpp:12:24: note: initializing argument 2 of 'int hossz(int&, int&)'
12 | int hossz(int& x, int& l){
| ~~~~~^
main.cpp: In function 'void loopcheck(int&)':
main.cpp:26:14: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
26 | hossz(x, 1);
| ^
main.cpp:12:24: note: initializing argument 2 of 'int hossz(int&, int&)'
12 | int hossz(int& x, int& l){
| ~~~~~^