257692026-03-01 20:45:08algoproLegtávolabbi leszármazottcpp17Accepted 50/5057ms11060 KiB
// UUID: 3d51dfc8-75ad-4532-9382-1c8444a7cf33
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

pair<int, int> dfs (int tav, int cs, vector<vector<int>>& gyerek, pair<int, int> best){
    if (gyerek[cs].empty()) return {tav, cs};
    for(int gy : gyerek[cs]){
        pair<int, int> akt = dfs(tav+1, gy, gyerek,best);
        if (best.first < akt.first) best = akt;
        //cout<<best.first<<' '<<best.second<<'\n';
    }
    return best;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >>n;

    vector<bool>fo(n, true);
    vector<vector<int>>gyerek(n+1);

    for(int i = 0; i <n; i++){
        int a, gy;
        cin >>a >>gy;
        gyerek[a].push_back(gy);
        fo[gy-1] = false;
    }
    int csf = -1;
    for(int i = 0; i <n; i++){
        if(fo[i]) csf = i+1;
    }
    pair<int, int> best =  dfs(0,csf,gyerek,{0, csf});

    cout<<best.second;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/037ms3744 KiB
3Accepted1/11ms316 KiB
4Accepted3/32ms316 KiB
5Accepted3/31ms316 KiB
6Accepted1/11ms316 KiB
7Accepted1/11ms316 KiB
8Accepted1/12ms316 KiB
9Accepted2/245ms4264 KiB
10Accepted3/339ms4372 KiB
11Accepted3/31ms500 KiB
12Accepted4/450ms7724 KiB
13Accepted4/448ms7792 KiB
14Accepted3/34ms820 KiB
15Accepted3/357ms7596 KiB
16Accepted3/348ms8080 KiB
17Accepted3/352ms7552 KiB
18Accepted4/435ms5148 KiB
19Accepted4/437ms7220 KiB
20Accepted4/450ms11060 KiB