60602023-10-29 08:31:17GervidLegtávolabbi leszármazottcpp17Time limit exceeded 21/50400ms10480 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

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

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

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

        connections[temp2] = temp1;

        been[temp1] = true;
    }

    queue<vector<int>> steps;

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

    int max = 0, maxi;

    while (steps.size() > 0)
    {
        if (connections[steps.front()[1]] == -1)
        {
            max = steps.front()[2] + 1;
            maxi = steps.front()[0];
        }
        else
        {
            if (distance[connections[steps.front()[1]]] < steps.front()[2] + 1)
            {
                steps.push({ steps.front()[0], connections[steps.front()[1]], steps.front()[2] + 1 });
                distance[connections[steps.front()[1]]] = steps.front()[2] + 1;
            }
        }
        steps.pop();
    }

    cout << maxi + 1;
}
//8
//1 4
//5 7
//8 6
//8 5
//3 1
//3 2
//3 8
SubtaskSumTestVerdictTimeMemory
base21/50
1Accepted0/03ms1816 KiB
2Accepted0/075ms8288 KiB
3Accepted1/13ms2224 KiB
4Accepted3/33ms2480 KiB
5Accepted3/33ms2668 KiB
6Accepted1/13ms2916 KiB
7Accepted1/13ms3104 KiB
8Accepted1/13ms3212 KiB
9Accepted2/282ms10340 KiB
10Accepted3/381ms10480 KiB
11Accepted3/33ms3620 KiB
12Time limit exceeded0/4400ms5636 KiB
13Time limit exceeded0/4381ms5720 KiB
14Accepted3/39ms4416 KiB
15Time limit exceeded0/3400ms4836 KiB
16Time limit exceeded0/3381ms5308 KiB
17Time limit exceeded0/3377ms5948 KiB
18Time limit exceeded0/4365ms4860 KiB
19Time limit exceeded0/4349ms5564 KiB
20Time limit exceeded0/4368ms4696 KiB