# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
295024 | 2020-09-09T12:30:07 Z | thebes | Inspection (POI11_ins) | C++14 | 1737 ms | 92636 KB |
#include <bits/stdc++.h> using namespace std; const int MN = 1e6+5; int N, i, x, y, sz[MN], mx[MN]; vector<int> adj[MN], dis; long long ans[MN]; int dfs(int n,int p){ sz[n] = 1; for(auto v : adj[n]){ if(v==p) continue; sz[n] += dfs(v, n); mx[n] = max(mx[n], sz[v]); } return sz[n]; } void acc(int n,int p,int d){ dis.push_back(d); for(auto v : adj[n]){ if(v==p) continue; acc(v, n, d+1); } } void dfs2(int n,int p){ if(2*mx[n]<=N&&2*(N-sz[n])<=N){ dis.clear(); acc(n, 0, 0); sort(dis.begin(),dis.end()); for(auto v : dis) ans[n] += 2*v; ans[n] -= dis.back(); } else ans[n] = -1; for(auto v : adj[n]){ if(v==p) continue; dfs2(v, n); } } int main(){ scanf("%d",&N); for(i=1;i<N;i++){ scanf("%d%d",&x,&y); adj[x].push_back(y); adj[y].push_back(x); } dfs(1, 0); dfs2(1, 0); for(i=1;i<=N;i++) printf("%lld\n",ans[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 17 ms | 23808 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23808 KB | Output is correct |
2 | Incorrect | 17 ms | 23808 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 18 ms | 23928 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 25216 KB | Output is correct |
2 | Incorrect | 32 ms | 25600 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 47 ms | 26616 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 120 ms | 30760 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 831 ms | 58312 KB | Output is correct |
2 | Incorrect | 802 ms | 66024 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1709 ms | 92560 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1724 ms | 92576 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1737 ms | 92636 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |