Submission #1693025


Source Code Expand

import java.util.ArrayList;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		ArrayList<ArrayList<Integer>> llist=new ArrayList<ArrayList<Integer>>();
		int[] point=new int[n+1];
		for(int i=0;i<n;i++){
			ArrayList<Integer> list=new ArrayList<Integer>();
			llist.add(list);
		}//i番目は i-1番listを持つ
		for(int i=0;i<n-1;i++){
			llist.get(sc.nextInt()-1).add(i+2);
		}
		point[n]=1;
		for(int i=n-1;i>0;i--){
//			System.out.println(i);
			ArrayList<Integer> lis=llist.get(i-1);
			int size=lis.size();
			if(size==0){
				point[i]=1;
			}else{
				int max=0,min=Integer.MAX_VALUE;
				for(int j=0;j<size;j++){
					int ind=lis.get(j);
					int p=point[ind];
					max=(max<p)?p:max;
					min=(min>p)?p:min;
				}
				point[i]=max+min+1;
			}
		}
/*		for(int a:point){
			System.out.print(a+" ");
		}System.out.println();
*/		System.out.println(point[1]);
	}

}

Submission Info

Submission Time
Task C - 高橋君の給料
User ri2112
Language Java8 (OpenJDK 1.8.0)
Score 100
Code Size 1013 Byte
Status AC
Exec Time 116 ms
Memory 21844 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 4
AC × 22
Set Name Test Cases
Sample example_0.txt, example_1.txt, example_2.txt, example_3.txt
All example_0.txt, example_1.txt, example_2.txt, example_3.txt, maxrand_0.txt, maxrand_1.txt, maxrand_2.txt, random_0.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, special_0.txt, example_0.txt, example_1.txt, example_2.txt, example_3.txt
Case Name Status Exec Time Memory
example_0.txt AC 110 ms 19668 KB
example_1.txt AC 105 ms 18900 KB
example_2.txt AC 103 ms 21716 KB
example_3.txt AC 105 ms 18900 KB
maxrand_0.txt AC 103 ms 21716 KB
maxrand_1.txt AC 105 ms 19284 KB
maxrand_2.txt AC 105 ms 20820 KB
random_0.txt AC 103 ms 20692 KB
random_1.txt AC 105 ms 21204 KB
random_2.txt AC 104 ms 19156 KB
random_3.txt AC 106 ms 21076 KB
random_4.txt AC 107 ms 19540 KB
random_5.txt AC 105 ms 19540 KB
random_6.txt AC 106 ms 21716 KB
random_7.txt AC 102 ms 21076 KB
random_8.txt AC 116 ms 21844 KB
random_9.txt AC 105 ms 21076 KB
special_0.txt AC 109 ms 21204 KB