Submission #1602667
Source Code Expand
#include <iostream> #include <cmath> #include <cstdio> #include <algorithm> #include <vector> #include <queue> #include <set> #include <cassert> using namespace std; vector < vector < int > > graph; int n, A[100050], B[100050], d[100050]; /// round, depth, node set < int > s; priority_queue < pair < int, pair < int, int > > > q; vector < set < int > > child; void dfs(int node, int par, int dep) { d[node] = dep; if(!graph[node].size()) { B[node] = 1; q.push({-1, {-d[node], node}}); } for(int i = 0;i < graph[node].size();++i) { int to = graph[node][i]; if(to != par) dfs(to, node, dep + 1); } } int main() { scanf("%d", &n); graph.resize(n + 5); child.resize(n + 5); for(int i = 2;i < n + 1;++i) { scanf("%d", A + i); graph[A[i]].push_back(i); child[A[i]].insert(i); } dfs(1, -1, 0); int ans = 0; while(!q.empty()) { int round = -q.top().first; int dep = -q.top().second.first; int node = q.top().second.second; q.pop(); ans = max(ans, round); if(node == 1) break; if(round > B[A[node]]) { child[A[node]].erase(node); if(!child[A[node]].size()) q.push({-round - 1, {-d[A[node]], A[node]}}); B[A[node]] = round; } else q.push({-round - 1, {-d[node], node}}); } printf("%d\n", ans - 1); return 0; } /* 9 1 1 2 4 2 2 7 7 */
Submission Info
Submission Time | |
---|---|
Task | B - Tournament |
User | vjudge3 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1550 Byte |
Status | TLE |
Exec Time | 2105 ms |
Memory | 24064 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:38:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:43:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", A + i); ^
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 | AC | 67 ms | 15612 KB |
02.txt | AC | 68 ms | 15612 KB |
03.txt | AC | 67 ms | 15612 KB |
04.txt | AC | 68 ms | 15612 KB |
05.txt | AC | 67 ms | 15612 KB |
06.txt | AC | 65 ms | 15612 KB |
07.txt | AC | 68 ms | 15612 KB |
08.txt | AC | 67 ms | 15612 KB |
09.txt | AC | 65 ms | 15612 KB |
10.txt | AC | 72 ms | 15612 KB |
11.txt | AC | 35 ms | 24064 KB |
12.txt | AC | 38 ms | 21116 KB |
13.txt | AC | 40 ms | 19708 KB |
14.txt | AC | 43 ms | 18300 KB |
15.txt | AC | 45 ms | 17788 KB |
16.txt | AC | 46 ms | 17020 KB |
17.txt | AC | 48 ms | 16508 KB |
18.txt | AC | 50 ms | 16124 KB |
19.txt | AC | 55 ms | 15992 KB |
20.txt | AC | 65 ms | 15996 KB |
21.txt | TLE | 2104 ms | 17136 KB |
22.txt | TLE | 2104 ms | 15280 KB |
23.txt | TLE | 2105 ms | 15212 KB |
24.txt | TLE | 2104 ms | 15224 KB |
25.txt | TLE | 2104 ms | 15224 KB |
26.txt | TLE | 2104 ms | 15224 KB |
27.txt | TLE | 2104 ms | 15224 KB |
28.txt | TLE | 2105 ms | 15356 KB |
29.txt | TLE | 2089 ms | 15352 KB |
30.txt | AC | 901 ms | 15352 KB |
31.txt | AC | 48 ms | 15352 KB |
32.txt | AC | 56 ms | 15732 KB |
33.txt | AC | 61 ms | 15352 KB |
34.txt | AC | 75 ms | 15352 KB |
35.txt | AC | 95 ms | 15480 KB |
36.txt | AC | 138 ms | 15096 KB |
37.txt | AC | 240 ms | 14968 KB |
38.txt | AC | 695 ms | 15096 KB |
39.txt | TLE | 2104 ms | 15096 KB |
40.txt | TLE | 2104 ms | 14968 KB |
41.txt | AC | 1 ms | 256 KB |
42.txt | AC | 1 ms | 256 KB |
43.txt | AC | 1 ms | 256 KB |
44.txt | AC | 1 ms | 256 KB |
45.txt | AC | 1 ms | 256 KB |
46.txt | AC | 1 ms | 256 KB |
47.txt | AC | 1 ms | 256 KB |
48.txt | AC | 1 ms | 256 KB |
49.txt | AC | 1 ms | 256 KB |
50.txt | AC | 1 ms | 256 KB |
s1.txt | AC | 1 ms | 256 KB |
s2.txt | AC | 1 ms | 256 KB |
s3.txt | AC | 1 ms | 256 KB |