Submission #4396048
Source Code Expand
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.AGC_Challenge { class _009_B { static void Main(string[] args) { Method(args); ReadLine(); } static void Method(string[] args) { int n = ReadInt(); List<int>[] graph = new List<int>[n]; int[] childCnts = new int[n]; int[] parents = new int[n]; for (int i = 0; i < n; i++) graph[i] = new List<int>(); for (int i = 1; i < n; i++) { int a = ReadInt() - 1; graph[a].Add(i); childCnts[a]++; parents[i] = a; } int[] depthes = new int[n]; Queue<int> queue = new Queue<int>(); for(int i = 0; i < n; i++) { if (childCnts[i] == 0) queue.Enqueue(i); } while (queue.Count > 0) { int now = queue.Dequeue(); int[] nowDepthes = new int[graph[now].Count]; for(int i = 0; i < nowDepthes.Length; i++) { nowDepthes[i] = depthes[graph[now][i]]; } Array.Sort(nowDepthes); int depth = 0; for (int i = 0; i < nowDepthes.Length; i++) { if (depth >= nowDepthes[i]) depth++; else depth = nowDepthes[i] + 1; } depthes[now] = depth; //WriteLine(now + ":" + depth); if (now != 0) { childCnts[parents[now]]--; if (childCnts[parents[now]] == 0) { queue.Enqueue(parents[now]); } } } WriteLine(depthes[0]); } static int GetDepth(List<int>[] graph,ref int[] depthes, int now) { if (depthes[now] >= 0) return depthes[now]; int len = graph[now].Count; if (len == 0) return 0; int[] nowDepthes = new int[len]; for (int i = 0; i < len; i++) { nowDepthes[i] = GetDepth(graph, ref depthes, graph[now][i]); } Array.Sort(nowDepthes); int depth = 0; for (int i = 0; i < len; i++) { if (depth >= nowDepthes[i]) depth++; else depth = nowDepthes[i] + 1; } depthes[now] = depth; return depth; } private static string Read() { return ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
Submission Info
Submission Time | |
---|---|
Task | B - Tournament |
User | MiuraMiuMiu |
Language | C# (Mono 4.6.2.0) |
Score | 800 |
Code Size | 3399 Byte |
Status | AC |
Exec Time | 98 ms |
Memory | 28832 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 | 95 ms | 24228 KB |
02.txt | AC | 94 ms | 26276 KB |
03.txt | AC | 94 ms | 24228 KB |
04.txt | AC | 98 ms | 24228 KB |
05.txt | AC | 95 ms | 26276 KB |
06.txt | AC | 93 ms | 24228 KB |
07.txt | AC | 98 ms | 26276 KB |
08.txt | AC | 94 ms | 24228 KB |
09.txt | AC | 95 ms | 24228 KB |
10.txt | AC | 94 ms | 24228 KB |
11.txt | AC | 85 ms | 26020 KB |
12.txt | AC | 85 ms | 24996 KB |
13.txt | AC | 89 ms | 24868 KB |
14.txt | AC | 90 ms | 24740 KB |
15.txt | AC | 90 ms | 22692 KB |
16.txt | AC | 91 ms | 28832 KB |
17.txt | AC | 89 ms | 24740 KB |
18.txt | AC | 92 ms | 26788 KB |
19.txt | AC | 93 ms | 22692 KB |
20.txt | AC | 89 ms | 22692 KB |
21.txt | AC | 78 ms | 23716 KB |
22.txt | AC | 77 ms | 23716 KB |
23.txt | AC | 78 ms | 22180 KB |
24.txt | AC | 78 ms | 28068 KB |
25.txt | AC | 77 ms | 21668 KB |
26.txt | AC | 79 ms | 27812 KB |
27.txt | AC | 79 ms | 25764 KB |
28.txt | AC | 78 ms | 25000 KB |
29.txt | AC | 78 ms | 22820 KB |
30.txt | AC | 79 ms | 21028 KB |
31.txt | AC | 84 ms | 24100 KB |
32.txt | AC | 81 ms | 27936 KB |
33.txt | AC | 78 ms | 21412 KB |
34.txt | AC | 79 ms | 23328 KB |
35.txt | AC | 79 ms | 25376 KB |
36.txt | AC | 81 ms | 22820 KB |
37.txt | AC | 77 ms | 20644 KB |
38.txt | AC | 76 ms | 24996 KB |
39.txt | AC | 77 ms | 24872 KB |
40.txt | AC | 79 ms | 20772 KB |
41.txt | AC | 23 ms | 11348 KB |
42.txt | AC | 23 ms | 13396 KB |
43.txt | AC | 23 ms | 11348 KB |
44.txt | AC | 23 ms | 11348 KB |
45.txt | AC | 23 ms | 11348 KB |
46.txt | AC | 22 ms | 9300 KB |
47.txt | AC | 23 ms | 11348 KB |
48.txt | AC | 23 ms | 11348 KB |
49.txt | AC | 23 ms | 13396 KB |
50.txt | AC | 23 ms | 9300 KB |
s1.txt | AC | 22 ms | 9300 KB |
s2.txt | AC | 22 ms | 9300 KB |
s3.txt | AC | 22 ms | 9300 KB |