213152026-01-12 18:23:40algoproLegtávolabbi leszármazottcpp17Wrong answer 1/5090ms7220 KiB
// UUID: 7f3678ac-4c81-4745-8800-ec9a04397772
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> csaladfa;

int legtavolabbi(int szemely) {
    if (csaladfa[szemely].empty()) return szemely;
    int tavoli = szemely;
    for (int gyerek : csaladfa[szemely]) {
        tavoli = legtavolabbi(gyerek);
    }
    return tavoli;
}

int main() {
    int n;
    cin >> n;
    csaladfa.resize(n + 1);
    vector<bool> szulo(n + 1, false);

    for (int i = 0; i < n - 1; i++) {
        int apa, fia;
        cin >> apa >> fia;
        csaladfa[apa].push_back(fia);
        szulo[fia] = true;
    }

    int gyoker = 0;
    for(int i = 1; i <= n; i++){
        if(!szulo[i]){
            gyoker = i;
            break;
        }
    }

    cout << legtavolabbi(gyoker);
}
SubtaskSumTestVerdictTimeMemory
base1/50
1Accepted0/01ms316 KiB
2Wrong answer0/079ms3888 KiB
3Accepted1/11ms316 KiB
4Wrong answer0/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Wrong answer0/11ms316 KiB
7Wrong answer0/11ms500 KiB
8Wrong answer0/11ms316 KiB
9Wrong answer0/285ms4288 KiB
10Wrong answer0/382ms4268 KiB
11Wrong answer0/31ms316 KiB
12Wrong answer0/487ms5700 KiB
13Wrong answer0/486ms5684 KiB
14Wrong answer0/38ms564 KiB
15Wrong answer0/385ms5624 KiB
16Wrong answer0/381ms5536 KiB
17Wrong answer0/385ms5248 KiB
18Wrong answer0/464ms4176 KiB
19Wrong answer0/475ms4916 KiB
20Wrong answer0/490ms7220 KiB