Submission #1755488
Source Code Expand
#include<bits/stdc++.h> #define N 100005 using namespace std; typedef pair<int,int> P; vector<int> G[N]; int n, par[N], dep[N], chinum[N]; priority_queue<P> q; int dfs(int x, int d){ dep[x] = d; int res = 0; for(int i=0;i<G[x].size();i++){ int nx = G[x][i]; res += dfs(nx, d+1); } if(!res) res = 1, chinum[x] = 0; else chinum[x] = res; return res; } bool used[N]; int cnt[N]; void solve(){ for(int i=1;i<n;i++) if(chinum[i]==cnt[i]) q.push(P(dep[i], i)); vector<P> tmp; int ans=0; while(!q.empty()){ while(!q.empty()){ P t = q.top(); q.pop(); int node = t.second; if(!used[par[node]]&&cnt[node]==chinum[node]){ used[par[node]]=true; cnt[par[node]] += cnt[node]+1; if(cnt[par[node]]==chinum[par[node]]) tmp.push_back(P(dep[par[node]], par[node])); } else tmp.push_back(t); } for(int i=0;i<tmp.size();i++) q.push(tmp[i]); memset(used,0,sizeof(used)); tmp.clear(); ans++; } cout<<ans<<endl; } int main(){ cin>>n; for(int i=0;i<n-1;i++){ int a; scanf("%d", &a); G[a-1].push_back(i+1); par[i+1] = a-1; } dfs(0,0); solve(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Tournament |
User | Gacho_0716 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1309 Byte |
Status | WA |
Exec Time | 2108 ms |
Memory | 13184 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:74:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &a); ^
Judge Result
Set Name | Sample | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 800 | ||||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, s1.txt, s2.txt, s3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | TLE | 2104 ms | 6780 KB |
02.txt | TLE | 2104 ms | 6780 KB |
03.txt | TLE | 2104 ms | 6776 KB |
04.txt | TLE | 2104 ms | 6780 KB |
05.txt | TLE | 2104 ms | 6780 KB |
06.txt | TLE | 2104 ms | 6780 KB |
07.txt | TLE | 2104 ms | 6780 KB |
08.txt | TLE | 2104 ms | 6780 KB |
09.txt | TLE | 2104 ms | 6780 KB |
10.txt | TLE | 2104 ms | 6776 KB |
11.txt | WA | 22 ms | 13184 KB |
12.txt | WA | 24 ms | 11132 KB |
13.txt | TLE | 2104 ms | 9980 KB |
14.txt | TLE | 2104 ms | 8956 KB |
15.txt | TLE | 2104 ms | 8316 KB |
16.txt | TLE | 2104 ms | 7676 KB |
17.txt | TLE | 2104 ms | 7292 KB |
18.txt | TLE | 2104 ms | 7036 KB |
19.txt | TLE | 2104 ms | 6908 KB |
20.txt | TLE | 2104 ms | 6904 KB |
21.txt | TLE | 2108 ms | 6516 KB |
22.txt | TLE | 2104 ms | 6428 KB |
23.txt | TLE | 2104 ms | 6508 KB |
24.txt | TLE | 2104 ms | 6904 KB |
25.txt | TLE | 2104 ms | 6552 KB |
26.txt | TLE | 2104 ms | 6584 KB |
27.txt | TLE | 2104 ms | 6644 KB |
28.txt | TLE | 2104 ms | 6644 KB |
29.txt | WA | 1273 ms | 6644 KB |
30.txt | WA | 529 ms | 6652 KB |
31.txt | WA | 30 ms | 6392 KB |
32.txt | WA | 36 ms | 6388 KB |
33.txt | WA | 40 ms | 6260 KB |
34.txt | WA | 50 ms | 6772 KB |
35.txt | WA | 64 ms | 6900 KB |
36.txt | WA | 93 ms | 6516 KB |
37.txt | WA | 159 ms | 6520 KB |
38.txt | WA | 478 ms | 6644 KB |
39.txt | AC | 1752 ms | 6644 KB |
40.txt | TLE | 2104 ms | 6524 KB |
41.txt | WA | 2 ms | 2688 KB |
42.txt | WA | 2 ms | 2688 KB |
43.txt | WA | 2 ms | 2688 KB |
44.txt | AC | 2 ms | 2688 KB |
45.txt | WA | 2 ms | 2688 KB |
46.txt | AC | 2 ms | 2688 KB |
47.txt | WA | 2 ms | 2688 KB |
48.txt | AC | 2 ms | 2688 KB |
49.txt | AC | 2 ms | 2688 KB |
50.txt | AC | 2 ms | 2688 KB |
s1.txt | WA | 2 ms | 2688 KB |
s2.txt | AC | 2 ms | 2688 KB |
s3.txt | AC | 2 ms | 2688 KB |