71232023-12-31 10:09:39MagyarKendeSZLGLegtávolabbi leszármazottcpp17Accepted 50/5039ms14124 KiB
#include <bits/stdc++.h>

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define cinv(v) for (auto& e : v) cin >> e;
#define all(v) v.begin(), v.end()
#define has(s, e) s.count(e)

using namespace std;
using ll = long long;
using point = array<int, 2>;

int main() {
    speed;

    vector<vector<int>> g;
    vector<bool> has_father;
    int N;
    cin >> N;
    g.resize(N + 1);
    has_father.resize(N + 1);
    for (int i = 1; i < N; i++) {
        int U, V;
        cin >> U >> V;
        g[U].push_back(V);
        has_father[V] = 1;
    }

    int root;
    for (int i = 1 ; i <= N; i++) {
        if (!has_father[i]) {
            root = i;
            break;
        }
    }

    queue<int> q;
    q.push(root);
    int next;

    while (!q.empty()) {
        next = q.front();
        q.pop();
        for (int son : g[next]) {
            q.push(son);
        }
    }

    cout << next;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/032ms9244 KiB
3Accepted1/13ms2268 KiB
4Accepted3/33ms2320 KiB
5Accepted3/33ms2540 KiB
6Accepted1/13ms2568 KiB
7Accepted1/13ms2776 KiB
8Accepted1/13ms3156 KiB
9Accepted2/237ms11292 KiB
10Accepted3/337ms11568 KiB
11Accepted3/33ms3772 KiB
12Accepted4/439ms12448 KiB
13Accepted4/437ms12684 KiB
14Accepted3/36ms4648 KiB
15Accepted3/337ms12640 KiB
16Accepted3/334ms11996 KiB
17Accepted3/337ms11992 KiB
18Accepted4/427ms10508 KiB
19Accepted4/432ms11080 KiB
20Accepted4/439ms14124 KiB