42632023-03-20 19:59:16horvathabelLegtávolabbi leszármazottcpp17Accepted 50/5085ms16148 KiB
#include <bits/stdc++.h>
using namespace std;
vector<int> g[100001];
int bfs(int x){
	pair<int, int> mx={0,0};
	queue<int> q;
	int t[100001];
	q.push(x);
	while (!q.empty()){
		int v=q.front();
		q.pop(); 
		for (int edge:g[v]){
			t[edge]=t[v]+1;
			if (t[edge]>mx.first) mx={t[edge],edge};
			q.push(edge);
		}
	}
	return mx.second;
}
int main() {
	int n;
	cin>>n;
	vector<int> c(n+1);
	for (int i=1; i<n;i++){
		int x,y;
		cin>>x>>y;
		c[y]++;
		g[x].push_back(y); 
	}
	for (int i=1; i<=n;i++){
		if (c[i]==0) {
			cout<<bfs(i);
			return 0; 
		}
	}
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/04ms7232 KiB
2Accepted0/072ms11148 KiB
3Accepted1/14ms7764 KiB
4Accepted3/34ms7972 KiB
5Accepted3/34ms7932 KiB
6Accepted1/14ms8188 KiB
7Accepted1/14ms8512 KiB
8Accepted1/14ms8760 KiB
9Accepted2/279ms12464 KiB
10Accepted3/379ms12720 KiB
11Accepted3/34ms9172 KiB
12Accepted4/482ms14068 KiB
13Accepted4/482ms14116 KiB
14Accepted3/310ms9848 KiB
15Accepted3/375ms14824 KiB
16Accepted3/375ms14036 KiB
17Accepted3/378ms13900 KiB
18Accepted4/461ms13504 KiB
19Accepted4/471ms13692 KiB
20Accepted4/485ms16148 KiB