Submission #2007251
Source Code Expand
import java.io.*; import java.util.*; import java.math.*; // import java.awt.Point; public class Main { InputStream is; PrintWriter out; String INPUT = ""; long MOD = 1_000_000_007; long inf = Long.MAX_VALUE; ArrayList<Integer>[] Edge; void solve(){ int n = ni(); Edge = new ArrayList[n]; for(int i = 0; i < n; i++){ Edge[i] = new ArrayList<>(); } for(int i = 1; i < n; i++){ int from = ni()-1; int to = i; Edge[from].add(to); } out.println(dfs(0)); } int dfs(int cur){ if(Edge[cur].size()==0) return 0; int[] res = new int[Edge[cur].size()]; int p = 0; for(int i : Edge[cur]){ res[p] = dfs(i); p++; } Arrays.sort(res); for(int i = 0; i < Edge[cur].size(); i++){ res[i] += Edge[cur].size()-i; } Arrays.sort(res); return res[Edge[cur].size()-1]; } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new Main().run(); } private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b) && b != ' ')){ sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } }
Submission Info
Submission Time | |
---|---|
Task | B - Tournament |
User | yuya178 |
Language | Java8 (OpenJDK 1.8.0) |
Score | 800 |
Code Size | 4214 Byte |
Status | AC |
Exec Time | 216 ms |
Memory | 75608 KB |
Compile Error
Note: ./Main.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
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 | 142 ms | 31396 KB |
02.txt | AC | 136 ms | 31508 KB |
03.txt | AC | 120 ms | 31028 KB |
04.txt | AC | 134 ms | 34868 KB |
05.txt | AC | 132 ms | 33320 KB |
06.txt | AC | 131 ms | 30596 KB |
07.txt | AC | 139 ms | 31804 KB |
08.txt | AC | 138 ms | 30448 KB |
09.txt | AC | 135 ms | 32252 KB |
10.txt | AC | 136 ms | 30880 KB |
11.txt | AC | 216 ms | 75608 KB |
12.txt | AC | 132 ms | 48848 KB |
13.txt | AC | 123 ms | 46292 KB |
14.txt | AC | 139 ms | 41160 KB |
15.txt | AC | 119 ms | 37080 KB |
16.txt | AC | 135 ms | 39308 KB |
17.txt | AC | 130 ms | 29800 KB |
18.txt | AC | 134 ms | 34772 KB |
19.txt | AC | 138 ms | 33728 KB |
20.txt | AC | 135 ms | 31752 KB |
21.txt | AC | 134 ms | 26980 KB |
22.txt | AC | 142 ms | 26812 KB |
23.txt | AC | 141 ms | 29128 KB |
24.txt | AC | 132 ms | 26164 KB |
25.txt | AC | 140 ms | 28948 KB |
26.txt | AC | 131 ms | 27296 KB |
27.txt | AC | 133 ms | 27128 KB |
28.txt | AC | 128 ms | 28132 KB |
29.txt | AC | 131 ms | 26864 KB |
30.txt | AC | 126 ms | 31972 KB |
31.txt | AC | 116 ms | 29872 KB |
32.txt | AC | 113 ms | 29112 KB |
33.txt | AC | 124 ms | 26244 KB |
34.txt | AC | 122 ms | 28804 KB |
35.txt | AC | 122 ms | 28084 KB |
36.txt | AC | 122 ms | 28844 KB |
37.txt | AC | 135 ms | 29052 KB |
38.txt | AC | 125 ms | 27308 KB |
39.txt | AC | 124 ms | 27532 KB |
40.txt | AC | 124 ms | 28616 KB |
41.txt | AC | 70 ms | 20180 KB |
42.txt | AC | 70 ms | 21076 KB |
43.txt | AC | 68 ms | 18004 KB |
44.txt | AC | 69 ms | 19156 KB |
45.txt | AC | 69 ms | 20948 KB |
46.txt | AC | 70 ms | 18132 KB |
47.txt | AC | 68 ms | 17748 KB |
48.txt | AC | 69 ms | 21076 KB |
49.txt | AC | 68 ms | 21204 KB |
50.txt | AC | 70 ms | 16852 KB |
s1.txt | AC | 70 ms | 20948 KB |
s2.txt | AC | 70 ms | 21076 KB |
s3.txt | AC | 67 ms | 21332 KB |