#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
#define int ll
#define fore(i, a, b) for(int i=a; i<b; ++i)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define vi vector<int>
const int N = 205;
vi adj[N];
int n;
int taken[N];
int dfs(int x, int prev=-1){
int tam = 1;
for(int child : adj[x]){
if(child == prev) continue;
tam += dfs(child, x);
}
if(taken[x]){
taken[x] = tam;
tam = 0;
}
return tam;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
if(n <= 200){
fore(i, 0, n-1){
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
int ans = 1e9;
taken[1] = 1;
for(int i=2; i<=n; ++i){
for(int j=i+1; j<=n; ++j){
taken[1] = taken[i] = taken[j] = 1;
dfs(1);
ans = min(ans, max({taken[1],taken[i],taken[j]}) - min({taken[1],taken[i],taken[j]}));
taken[1] = taken[i] = taken[j] = 0;
}
}
cout << ans;
return 0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
344 KB |
Output is correct |
2 |
Correct |
19 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
344 KB |
Output is correct |
4 |
Correct |
16 ms |
348 KB |
Output is correct |
5 |
Correct |
18 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
344 KB |
Output is correct |
2 |
Correct |
19 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
344 KB |
Output is correct |
4 |
Correct |
16 ms |
348 KB |
Output is correct |
5 |
Correct |
18 ms |
468 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
344 KB |
Output is correct |
2 |
Correct |
19 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
344 KB |
Output is correct |
4 |
Correct |
16 ms |
348 KB |
Output is correct |
5 |
Correct |
18 ms |
468 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |