#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
int N,Ans=INF;
int Size[2001];
vector<int> Edge[2001];
vector<pair<int,int>> Edge_List;
void dfs(int v,int par){
Size[v]=1;
for (int i:Edge[v]){
if (i==par)
continue;
dfs(i,v);
Size[v]+=Size[i];
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>N;
for (int i=1; i<N; i++){
int a,b;
cin>>a>>b;
Edge[a].push_back(b);
Edge[b].push_back(a);
Edge_List.push_back({a,b});
}
for (auto i:Edge_List){
for (int i=1; i<=N; i++)
Size[i]=0;
dfs(i.second,i.first);
for (int j=1; j<=N; j++){
if (!Size[j]||j==i.second)
continue;
Ans=min(Ans,max({Size[j],Size[i.second]-Size[j],N-Size[i.second]})-min({Size[j],Size[i.second]-Size[j],N-Size[i.second]}));
}
}
cout<<Ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
372 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
372 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
372 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |