Submission #1322460
Source Code Expand
import java.io.*; import java.math.*; import java.util.*; public class Main { private static boolean debug = false; private static boolean elapsed = false; private static PrintWriter _out = new PrintWriter(System.out); private static PrintWriter _err = new PrintWriter(System.err); private List<List<Integer>> list = new ArrayList<>(); private void solve(Scanner sc) { int N = sc.nextInt(); for (int i = 0; i < N; ++i) { list.add(new ArrayList<>()); } for (int i = 0; i < N - 1; ++i) { int a = sc.nextInt(); list.get(a - 1).add(i + 1); } _out.println(calc(0)); } private int calc(int v) { List<Integer> child = list.get(v); if (child.size() == 0) { return 0; } List<Integer> tmp = new ArrayList<>(); for (int u : child) { tmp.add(calc(u)); } Collections.sort(tmp); int res = 0; for (int i = 0; i < tmp.size(); ++i) { int u = tmp.get(i); res = Math.max(res, u + child.size() - i); } return res; } private static BigInteger C(long n, long r) { BigInteger res = BigInteger.ONE; for (long i = n; i > n - r; --i) { res = res.multiply(BigInteger.valueOf(i)); } for (long i = r; i > 1; --i) { res = res.divide(BigInteger.valueOf(i)); } return res; } private static BigInteger P(long n, long r) { BigInteger res = BigInteger.ONE; for (long i = n; i > n - r; --i) { res = res.multiply(BigInteger.valueOf(i)); } return res; } /* * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9 * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18 */ public static void main(String[] args) { long S = System.currentTimeMillis(); Scanner sc = new Scanner(System.in); new Main().solve(sc); _out.flush(); long G = System.currentTimeMillis(); if (elapsed) { _err.println((G - S) + "ms"); } _err.flush(); } }
Submission Info
Submission Time | |
---|---|
Task | B - Tournament |
User | unirita135 |
Language | Java8 (OpenJDK 1.8.0) |
Score | 800 |
Code Size | 2252 Byte |
Status | AC |
Exec Time | 531 ms |
Memory | 95084 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 | 508 ms | 63412 KB |
02.txt | AC | 489 ms | 65248 KB |
03.txt | AC | 513 ms | 63776 KB |
04.txt | AC | 518 ms | 65412 KB |
05.txt | AC | 483 ms | 64736 KB |
06.txt | AC | 511 ms | 61680 KB |
07.txt | AC | 508 ms | 63648 KB |
08.txt | AC | 512 ms | 63896 KB |
09.txt | AC | 479 ms | 66052 KB |
10.txt | AC | 526 ms | 64548 KB |
11.txt | AC | 531 ms | 95084 KB |
12.txt | AC | 493 ms | 79480 KB |
13.txt | AC | 503 ms | 75948 KB |
14.txt | AC | 526 ms | 78176 KB |
15.txt | AC | 485 ms | 71052 KB |
16.txt | AC | 466 ms | 68936 KB |
17.txt | AC | 513 ms | 68976 KB |
18.txt | AC | 528 ms | 65788 KB |
19.txt | AC | 529 ms | 65388 KB |
20.txt | AC | 498 ms | 65064 KB |
21.txt | AC | 449 ms | 62996 KB |
22.txt | AC | 447 ms | 65788 KB |
23.txt | AC | 439 ms | 64324 KB |
24.txt | AC | 446 ms | 64164 KB |
25.txt | AC | 452 ms | 62248 KB |
26.txt | AC | 443 ms | 60388 KB |
27.txt | AC | 461 ms | 63560 KB |
28.txt | AC | 467 ms | 65124 KB |
29.txt | AC | 473 ms | 63852 KB |
30.txt | AC | 479 ms | 62240 KB |
31.txt | AC | 472 ms | 62280 KB |
32.txt | AC | 483 ms | 66384 KB |
33.txt | AC | 488 ms | 64204 KB |
34.txt | AC | 475 ms | 65392 KB |
35.txt | AC | 481 ms | 62456 KB |
36.txt | AC | 449 ms | 64472 KB |
37.txt | AC | 483 ms | 63844 KB |
38.txt | AC | 448 ms | 62632 KB |
39.txt | AC | 454 ms | 64656 KB |
40.txt | AC | 462 ms | 61120 KB |
41.txt | AC | 96 ms | 21332 KB |
42.txt | AC | 92 ms | 21844 KB |
43.txt | AC | 94 ms | 19284 KB |
44.txt | AC | 92 ms | 21972 KB |
45.txt | AC | 94 ms | 19284 KB |
46.txt | AC | 93 ms | 18772 KB |
47.txt | AC | 93 ms | 19924 KB |
48.txt | AC | 93 ms | 20560 KB |
49.txt | AC | 93 ms | 21716 KB |
50.txt | AC | 92 ms | 19668 KB |
s1.txt | AC | 92 ms | 21972 KB |
s2.txt | AC | 94 ms | 21588 KB |
s3.txt | AC | 94 ms | 18768 KB |