#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
int n, ans;
int sum[100010];
vector<int> g[100010];
void dfs(int x, int p) {
sum[x] = 1;
for(auto i : g[x]) {
if(i == p) continue;
dfs(i, x);
sum[x] += sum[i];
}
}
void f(int x, int p, int s) {
int mx = n - sum[x] - s;
for(auto i : g[x]) {
if(i == p) continue;
mx = max(mx, sum[i]);
f(i, x, s);
}
ans = min(ans, mx + s);
}
int main() {
fast;
cin >> n;
for(int i=1; i<n; i++) {
int u, v;
cin >> u >> v;
g[u].eb(v);
g[v].eb(u);
}
int ret = 0;
for(int i=1; i<=n; i++) {
dfs(i, 0);
ans = inf;
for(auto j : g[i]) {
f(j, i, n - sum[j]);
}
ret = max(ret, ans);
}
cout << ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |