60612023-10-29 08:41:20GervidLegtávolabbi leszármazottcpp17Accepted 50/5085ms13852 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main()
{
    int n, i, temp1, temp2;
    cin >> n;

    vector<vector<int>> connections(n);
    vector<bool> been(n, 0);

    for (i = 1; i < n; i++)
    {
        cin >> temp1 >> temp2;
        temp1--, temp2--;

        connections[temp1].push_back(temp2);

        been[temp2] = true;
    }

    queue<int> steps;

    for (i = 0; i < n; i++)
    {
        if (!been[i])
        {
            steps.push(i);
            break;
        }
    }

    while (steps.size() > 0)
    {
        for (i = 0; i < connections[steps.front()].size(); i++)
        {
            steps.push(connections[steps.front()][i]);
        }

        if (steps.size() == 1)
        {
            cout << steps.front() + 1;
            return 0;
        }

        steps.pop();
    }
}
//8
//1 4
//5 7
//8 6
//8 5
//3 1
//3 2
//3 8
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1816 KiB
2Accepted0/074ms9072 KiB
3Accepted1/13ms2120 KiB
4Accepted3/33ms2316 KiB
5Accepted3/33ms2432 KiB
6Accepted1/13ms2596 KiB
7Accepted1/13ms2728 KiB
8Accepted1/13ms3104 KiB
9Accepted2/281ms10624 KiB
10Accepted3/381ms10880 KiB
11Accepted3/33ms3148 KiB
12Accepted4/482ms11752 KiB
13Accepted4/481ms11752 KiB
14Accepted3/38ms3820 KiB
15Accepted3/374ms11876 KiB
16Accepted3/371ms11100 KiB
17Accepted3/376ms11232 KiB
18Accepted4/459ms9800 KiB
19Accepted4/470ms10804 KiB
20Accepted4/485ms13852 KiB