43962023-03-27 13:07:01vááááLegtávolabbi leszármazottcpp17Time limit exceeded 21/50400ms12768 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    n--;
    vector<int> a[n+9];
    int w, u;
    string v[2];
    for (int i = 0; i < n+9; i++)
    {
        a[i] = vector<int>();
    }
    vector<int> fel;
    vector<int> le;
    for (int i = 0; i < n; i++)
    {
        cin >> v[0] >> v[1];
        w = stoi(v[0]);
        u = stoi(v[1]);
        fel.push_back(w);
        le.push_back(u);
        a[w].push_back(u);
    }
    fel.erase(set_difference(fel.begin(), fel.end(), le.begin(), le.end(), fel.begin()), fel.end());
    while (le.size() != 0)
    {
        fel.clear();
        fel.insert(fel.end(), le.begin(), le.end());
        le.clear();
        for (int i = 0; i < fel.size(); i++)
        {
            le.insert(le.end(), a[fel[i]].begin(), a[fel[i]].end());
        }
    }
    cout << fel[0] << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base21/50
1Accepted0/03ms1684 KiB
2Accepted0/087ms10308 KiB
3Accepted1/13ms2140 KiB
4Accepted3/33ms2356 KiB
5Accepted3/33ms2568 KiB
6Accepted1/12ms2648 KiB
7Accepted1/13ms2900 KiB
8Accepted1/14ms3164 KiB
9Accepted2/298ms12768 KiB
10Accepted3/396ms12728 KiB
11Accepted3/33ms3424 KiB
12Time limit exceeded0/4400ms8104 KiB
13Time limit exceeded0/4347ms8152 KiB
14Accepted3/39ms4936 KiB
15Time limit exceeded0/3400ms8452 KiB
16Time limit exceeded0/3356ms8132 KiB
17Time limit exceeded0/3360ms8484 KiB
18Time limit exceeded0/4363ms7712 KiB
19Time limit exceeded0/4342ms8216 KiB
20Time limit exceeded0/4379ms9832 KiB