Submission #5496921
Source Code Expand
#include <bits/stdc++.h> #define pb push_back #define ppb pop_back #define fi first #define se second #define mid ((x + y) / 2) #define left (ind * 2) #define right (ind * 2 + 1) #define mp make_pair #define timer ((double)clock() / CLOCKS_PER_SEC) #define endl "\n" #define spc " " #define d1(x) cerr<<#x<<":"<<x<<endl #define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl #define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl #define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; typedef long long int lli; typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<double, double> dd; const int N = (int)(1e6 + 5); const int LOG = (int)(20); int n, dp[N]; vector<int> v[N]; void dfs(int x) { int re = 0; for(auto i : v[x]) dfs(i); sort(v[x].begin(), v[x].end(), [&] (int a, int b) { return dp[a] < dp[b]; }); reverse(v[x].begin(), v[x].end()); for(int i = 0; i < v[x].size(); i++) re = max(dp[v[x][i]] + i + 1, re); dp[x] = re; } int main() { fast_io(); // freopen("inp.in", "r", stdin); cin >> n; for(int i = 2; i <= n; i++) { int a; cin >> a; v[a].pb(i); } dfs(1); cout << dp[1]; }
Submission Info
Submission Time | |
---|---|
Task | B - Tournament |
User | Kewo |
Language | C++14 (GCC 5.4.1) |
Score | 800 |
Code Size | 1248 Byte |
Status | AC |
Exec Time | 30 ms |
Memory | 34176 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 800 / 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 | 29 ms | 26496 KB |
02.txt | AC | 30 ms | 26496 KB |
03.txt | AC | 29 ms | 26496 KB |
04.txt | AC | 30 ms | 26496 KB |
05.txt | AC | 29 ms | 26496 KB |
06.txt | AC | 30 ms | 26496 KB |
07.txt | AC | 30 ms | 26496 KB |
08.txt | AC | 30 ms | 26496 KB |
09.txt | AC | 29 ms | 26496 KB |
10.txt | AC | 30 ms | 26496 KB |
11.txt | AC | 28 ms | 34176 KB |
12.txt | AC | 27 ms | 31360 KB |
13.txt | AC | 27 ms | 30208 KB |
14.txt | AC | 27 ms | 29056 KB |
15.txt | AC | 26 ms | 28288 KB |
16.txt | AC | 26 ms | 27648 KB |
17.txt | AC | 26 ms | 27264 KB |
18.txt | AC | 27 ms | 26880 KB |
19.txt | AC | 28 ms | 26880 KB |
20.txt | AC | 28 ms | 26880 KB |
21.txt | AC | 17 ms | 25468 KB |
22.txt | AC | 17 ms | 25384 KB |
23.txt | AC | 17 ms | 25472 KB |
24.txt | AC | 17 ms | 25472 KB |
25.txt | AC | 17 ms | 25344 KB |
26.txt | AC | 18 ms | 25344 KB |
27.txt | AC | 19 ms | 25344 KB |
28.txt | AC | 18 ms | 25344 KB |
29.txt | AC | 19 ms | 25472 KB |
30.txt | AC | 20 ms | 25344 KB |
31.txt | AC | 23 ms | 26368 KB |
32.txt | AC | 22 ms | 25856 KB |
33.txt | AC | 21 ms | 25600 KB |
34.txt | AC | 21 ms | 25600 KB |
35.txt | AC | 21 ms | 25728 KB |
36.txt | AC | 19 ms | 25344 KB |
37.txt | AC | 19 ms | 25344 KB |
38.txt | AC | 18 ms | 25344 KB |
39.txt | AC | 18 ms | 25344 KB |
40.txt | AC | 17 ms | 25216 KB |
41.txt | AC | 9 ms | 24832 KB |
42.txt | AC | 9 ms | 24832 KB |
43.txt | AC | 9 ms | 24832 KB |
44.txt | AC | 9 ms | 24832 KB |
45.txt | AC | 9 ms | 24832 KB |
46.txt | AC | 9 ms | 24832 KB |
47.txt | AC | 9 ms | 24832 KB |
48.txt | AC | 9 ms | 24832 KB |
49.txt | AC | 9 ms | 24832 KB |
50.txt | AC | 9 ms | 24832 KB |
s1.txt | AC | 9 ms | 24832 KB |
s2.txt | AC | 9 ms | 24832 KB |
s3.txt | AC | 9 ms | 24832 KB |