60592023-10-29 08:02:59GervidLegtávolabbi leszármazottcpp17Time limit exceeded 4/50400ms18052 KiB
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

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

	vector<pair<int, int>> connections;

	int temp1, temp2;
	for (i = 0; i < n-1; i++)
	{
		cin >> temp1 >> temp2;
		connections.emplace_back(temp1, temp2);
	}

	bool* nemvolt = new bool[n - 1];
	for (i = 0; i < n - 1; i++)
	{
		nemvolt[i] = 1;
	}

	for (i = 0; i < n-1; i++)
	{
		nemvolt[connections[i].second-1] = 0;
	}

	vector<int> currentlayer;

	for (i = 0; i < n - 1; i++)
	{
		if (nemvolt[i] == 1)
		{
			currentlayer.push_back(i + 1);
		}
	}

	vector<int> nextlayer;

	while (true)
	{
		for (i = 0; i < n - 1; i++)
		{
			for (int j = 0; j < currentlayer.size(); j++)
			{
				if (connections[i].first == currentlayer[j])
				{
					nextlayer.push_back(connections[i].second);
				}
			}
		}

		if (nextlayer.size() == 1)
		{
			cout << nextlayer[0];
			return 0;
		}

		currentlayer = nextlayer;
		nextlayer.clear();
	}
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/03ms1808 KiB
2Time limit exceeded0/0361ms3380 KiB
3Time limit exceeded0/1372ms3284 KiB
4Wrong answer0/33ms3536 KiB
5Wrong answer0/33ms3752 KiB
6Accepted1/13ms3968 KiB
7Time limit exceeded0/1370ms4024 KiB
8Wrong answer0/13ms4144 KiB
9Time limit exceeded0/2400ms5808 KiB
10Time limit exceeded0/3363ms6908 KiB
11Time limit exceeded0/3340ms6824 KiB
12Time limit exceeded0/4370ms8284 KiB
13Time limit exceeded0/4374ms9560 KiB
14Accepted3/368ms9996 KiB
15Wrong answer0/363ms12912 KiB
16Wrong answer0/359ms14136 KiB
17Wrong answer0/364ms15212 KiB
18Wrong answer0/448ms16016 KiB
19Wrong answer0/457ms16960 KiB
20Wrong answer0/468ms18052 KiB