89912024-02-10 21:44:45xxxLegtávolabbi leszármazottcpp17Accepted 50/5086ms27364 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
	int n;
	cin >> n;
	vector<bool> gyereke(n+1, 0);
	vector<vector<int> > adj(n+1);
	for(int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		gyereke[y] = 1;
	}
	int os;
	for(int i = 1; i <= n; i++) {
		if (!gyereke[i]) {
			os = i;
			i = n+1;
		}
	}
	queue<int> q;
	vector<int> tav(n+1);
	q.push(os);
	int mxtav = -1, mxind;
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(int v : adj[u]) {
			tav[v] = tav[u]+1;
			if (tav[v] > mxtav) {
				mxtav = tav[v];
				mxind = v;
			}
			q.push(v);
		}
	}
	cout << mxind << ' ';



	
	
	return 0;
	
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1808 KiB
2Accepted0/071ms12024 KiB
3Accepted1/13ms2968 KiB
4Accepted3/33ms3212 KiB
5Accepted3/33ms3428 KiB
6Accepted1/13ms3644 KiB
7Accepted1/13ms4016 KiB
8Accepted1/13ms4256 KiB
9Accepted2/279ms15256 KiB
10Accepted3/379ms16384 KiB
11Accepted3/33ms6440 KiB
12Accepted4/482ms18232 KiB
13Accepted4/481ms19584 KiB
14Accepted3/39ms10036 KiB
15Accepted3/374ms20644 KiB
16Accepted3/372ms20656 KiB
17Accepted3/379ms22288 KiB
18Accepted4/457ms21140 KiB
19Accepted4/468ms23340 KiB
20Accepted4/486ms27364 KiB