43402023-03-25 15:54:07szilLegtávolabbi leszármazottcpp14Wrong answer 36/5056ms18388 KiB
#include <bits/stdc++.h>
 
using ll = long long;
using namespace std;

const int MAXN = 100001;

vector<int> g[MAXN];
int ans = 1, best = 0;

void dfs(int u, int p, int d) {
	if (best < d) {
		best = d;
		ans = u;
	}
	for (int v : g[u])
		if (v != p)
			dfs(v, u, d+1);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1, 0, 0);
	cout << ans << "\n";
}
SubtaskSumTestVerdictTimeMemory
base36/50
1Accepted0/04ms6672 KiB
2Accepted0/039ms12824 KiB
3Accepted1/14ms7076 KiB
4Wrong answer0/34ms7372 KiB
5Wrong answer0/34ms7676 KiB
6Accepted1/14ms7536 KiB
7Accepted1/14ms7676 KiB
8Accepted1/14ms8012 KiB
9Accepted2/241ms14600 KiB
10Accepted3/339ms14816 KiB
11Accepted3/34ms8360 KiB
12Accepted4/446ms17152 KiB
13Accepted4/446ms17360 KiB
14Accepted3/38ms9484 KiB
15Accepted3/343ms16216 KiB
16Accepted3/348ms15804 KiB
17Accepted3/356ms17076 KiB
18Wrong answer0/434ms14872 KiB
19Accepted4/439ms16348 KiB
20Wrong answer0/448ms18388 KiB