# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376269 | dantoh000 | Papričice (COCI20_papricice) | C++14 | 28 ms | 11756 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> G[2005];
int p[2005];
int sz[2005];
int d[2005][2005];
void dfs(int u){
sz[u] = 1;
for (auto v : G[u]){
if (v == p[u]) continue;
p[v] = u;
dfs(v);
sz[u] += sz[v];
}
}
int main(){
scanf("%d",&n);
for (int i = 0; i < n-1; i++){
int x,y;
scanf("%d%d",&x,&y);
G[x].push_back(y);
G[y].push_back(x);
}
p[1] = -1;
dfs(1);
for(int i =1; i <= n;i ++){
int cur = i;
while (cur != -1){
d[cur][i] = 1;
cur = p[cur];
}
}
int ans = n;
for (int i = 1; i <= n; i++){
for (int j = i+1; j <= n; j++){
int a = sz[i], b = sz[j];
if (d[i][j]) a -= b;
else if (d[j][i]) b -= a;
int c = n-a-b;
//printf("%d %d %d\n",a,b,c);
ans = min(ans, max(a,max(b,c)) - min(a,min(b,c)));
}
}
printf("%d",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |