Submission #376269

#TimeUsernameProblemLanguageResultExecution timeMemory
376269dantoh000Papričice (COCI20_papricice)C++14
50 / 110
28 ms11756 KiB
#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)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...