Submission #376269

# Submission time Handle Problem Language Result Execution time Memory
376269 2021-03-11T06:37:27 Z dantoh000 Papričice (COCI20_papricice) C++14
50 / 110
28 ms 11756 KB
#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

papricice.cpp: In function 'int main()':
papricice.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
papricice.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1260 KB Output is correct
2 Correct 1 ms 1260 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 1 ms 1260 KB Output is correct
5 Correct 2 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1260 KB Output is correct
2 Correct 1 ms 1260 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 1 ms 1260 KB Output is correct
5 Correct 2 ms 1260 KB Output is correct
6 Correct 23 ms 11244 KB Output is correct
7 Correct 24 ms 10732 KB Output is correct
8 Correct 22 ms 9580 KB Output is correct
9 Correct 22 ms 9580 KB Output is correct
10 Correct 28 ms 11756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1260 KB Output is correct
2 Correct 1 ms 1260 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 1 ms 1260 KB Output is correct
5 Correct 2 ms 1260 KB Output is correct
6 Correct 23 ms 11244 KB Output is correct
7 Correct 24 ms 10732 KB Output is correct
8 Correct 22 ms 9580 KB Output is correct
9 Correct 22 ms 9580 KB Output is correct
10 Correct 28 ms 11756 KB Output is correct
11 Runtime error 2 ms 492 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -