148042025-02-02 20:19:21mateLegtávolabbi leszármazottcpp17Accepted 50/50101ms9420 KiB
#include <bits/stdc++.h>
using namespace std;

vector < vector <int>> graf;
int maxi=0,maxi_csucs=0;

void dfs(int p, int mely){
    if(mely > maxi){
        maxi = mely;
        maxi_csucs = p;
    }
    for(int x : graf[p]){
        dfs(x, mely + 1);
    }
}

int main() {
	int n; cin >> n;
    graf.resize(n+1);
    vector <bool> bejovo(n+1,0);
    int a = 0,b;
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        graf[a].push_back(b);
        bejovo[b] = 1;
    }
    int gyoker = 0;
    for(int i = 1; i <= n; i++){
        if(!bejovo[i]){
            gyoker = i;
        }
    }
    dfs(gyoker, 0);
    cout << maxi_csucs;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/079ms4916 KiB
3Accepted1/11ms316 KiB
4Accepted3/31ms500 KiB
5Accepted3/31ms316 KiB
6Accepted1/11ms316 KiB
7Accepted1/11ms316 KiB
8Accepted1/11ms412 KiB
9Accepted2/282ms5368 KiB
10Accepted3/382ms5376 KiB
11Accepted3/31ms316 KiB
12Accepted4/492ms7220 KiB
13Accepted4/492ms7220 KiB
14Accepted3/38ms820 KiB
15Accepted3/397ms7100 KiB
16Accepted3/386ms7220 KiB
17Accepted3/390ms6996 KiB
18Accepted4/468ms5184 KiB
19Accepted4/475ms6672 KiB
20Accepted4/4101ms9420 KiB