20202022-12-14 18:55:43TomaSajtLegtávolabbi leszármazottcpp17Accepted 50/5041ms15232 KiB
#include <bits/stdc++.h>
#define speed ios::sync_with_stdio(0);cin.tie(0)
using namespace std;

int main() {
    speed;
    int n;
    cin >> n;
    vector<int> par(n + 1, -1);
    vector<vector<int>> children(n + 1);
    int u, v;
    while (cin >> u >> v) {
        par[v] = u;
        children[u].push_back(v);
    }
    int root = 0;
    for (int i = 1; i <= n; i++) {
        if (par[i] == -1) root = i;
    }
    queue<int> q;
    q.push(root);
    int last = -1;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v : children[u]) {
            q.push(v);
            last = v;
        }
    }
    cout << last;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1860 KiB
2Accepted0/032ms9796 KiB
3Accepted1/12ms2296 KiB
4Accepted3/32ms2452 KiB
5Accepted3/32ms2656 KiB
6Accepted1/12ms2860 KiB
7Accepted1/12ms3076 KiB
8Accepted1/13ms3420 KiB
9Accepted2/237ms11936 KiB
10Accepted3/339ms11932 KiB
11Accepted3/32ms3340 KiB
12Accepted4/435ms12660 KiB
13Accepted4/435ms12836 KiB
14Accepted3/34ms4464 KiB
15Accepted3/334ms13380 KiB
16Accepted3/332ms12520 KiB
17Accepted3/335ms12696 KiB
18Accepted4/426ms10920 KiB
19Accepted4/430ms12172 KiB
20Accepted4/441ms15232 KiB