0pts求条
查看原帖
0pts求条
791222
lby_commandBlock楼主2024/8/27 10:58
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int N = 1e5 + 9;

int n, ans;

bool vis[N];

vector<int> e[N];

void dfs(int S, int step) {
	for (auto i : e[S]) {
		if (!vis[i]) {
			vis[i] = true;
			dfs(i, step + 1);
			vis[i] = false;
		}
	}
	ans = max(ans, step);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
#ifdef BIG_BANANA_A_BIG_BANANA_YOUR_FEEL_VERY_WORDFUL
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif
	cin >> n;
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	for (int i = 1; i <= n; i++) {
		vis[i] = true;
		dfs(i, 0);
		vis[i] = false;
	}
	cout << ans << endl;
	return 0;
}
2024/8/27 10:58
加载中...