Submission #1602622


Source Code Expand

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cassert>

using namespace std;

vector < vector < int > > graph;
int n, A[100050], B[100050], d[100050];
///            round, depth, node
priority_queue < pair < int, pair < int, int > > > q;

void dfs(int node, int par, int dep)
{
    d[node] = dep;
    if(!graph[node].size())
    {
        B[node] = 1;
        q.push({0, {-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);
    for(int i = 2;i < n + 1;++i)
    {
        scanf("%d", A + i);
        graph[A[i]].push_back(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();

        assert(B[node] and "BUGG!!");
        ans = max(ans, round);
        if(node == 1)
            --B[node];

        else
        {
            if(!B[A[node]])
            {
                ++B[A[node]];
                --B[node];
                q.push({-round - 1, {-d[A[node]], A[node]}});
            }
            else
                q.push({-round - 1, {-d[node], node}});
        }
    }

    printf("%d\n", ans);

    return 0;
}

Submission Info

Submission Time
Task B - Tournament
User vjudge5
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1439 Byte
Status WA
Exec Time 2104 ms
Memory 14720 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:34:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:38: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
AC × 3
AC × 11
WA × 3
TLE × 39
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 6268 KB
02.txt TLE 2104 ms 6268 KB
03.txt TLE 2104 ms 6264 KB
04.txt TLE 2104 ms 6268 KB
05.txt TLE 2104 ms 6268 KB
06.txt TLE 2104 ms 6268 KB
07.txt TLE 2104 ms 6268 KB
08.txt TLE 2104 ms 6268 KB
09.txt TLE 2104 ms 6268 KB
10.txt TLE 2104 ms 6264 KB
11.txt AC 25 ms 14720 KB
12.txt TLE 2104 ms 11772 KB
13.txt TLE 2104 ms 10364 KB
14.txt TLE 2104 ms 8956 KB
15.txt TLE 2104 ms 8444 KB
16.txt TLE 2104 ms 7676 KB
17.txt TLE 2104 ms 7164 KB
18.txt TLE 2104 ms 6780 KB
19.txt TLE 2104 ms 6652 KB
20.txt TLE 2104 ms 6652 KB
21.txt TLE 2104 ms 5748 KB
22.txt TLE 2103 ms 5788 KB
23.txt TLE 2104 ms 5868 KB
24.txt TLE 2104 ms 5928 KB
25.txt TLE 2104 ms 5904 KB
26.txt TLE 2104 ms 5928 KB
27.txt TLE 2104 ms 5904 KB
28.txt TLE 2104 ms 6020 KB
29.txt TLE 2104 ms 6008 KB
30.txt TLE 2104 ms 6008 KB
31.txt TLE 2104 ms 6008 KB
32.txt TLE 2104 ms 6392 KB
33.txt TLE 2104 ms 6008 KB
34.txt TLE 2104 ms 6008 KB
35.txt TLE 2104 ms 6008 KB
36.txt TLE 2104 ms 5624 KB
37.txt TLE 2104 ms 5624 KB
38.txt TLE 2104 ms 5624 KB
39.txt TLE 2104 ms 5624 KB
40.txt TLE 2104 ms 5628 KB
41.txt WA 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 WA 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 WA 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