Submission #444764


Source Code Expand

import java.io.*;
import java.util.*;
import java.lang.ArrayIndexOutOfBoundsException;
import java.math.*;

/**
 * @author yoshikyoto
 * 
 * - 答えが int に収まりそうか注意
 * - Sample Input はちゃんと通ることを確認すべし
 */
class Main {
	static Scanner sc = new Scanner(new InputStreamReader(System.in));
	public static void main(String[] args) throws Exception {
		int n = sc.nextInt();
		Human[] humans = new Human[n];
		humans[0] = new Human();
		for (int i = 1; i < n; i++) {
			humans[i] = new Human();
			int b = sc.nextInt() - 1;
			humans[b].addChild(humans[i]);
		}
		System.out.println(humans[0].salary());
	}
}

class Human {
	ArrayList<Human> children;
	Human() {
		children = new ArrayList<Human>();
	}
	public void addChild(Human human) {
		children.add(human);
	}
	public int salary() {
		if(children.size() == 0) {
			return 1;
		}
		int ma = 1;
		int mi = 1<<28;
		for(Human human : children) {
			int salary = human.salary();
			ma = Math.max(ma, salary);
			mi = Math.min(mi, salary);
		}
		return (ma + mi + 1);
	}
}

Submission Info

Submission Time
Task C - 高橋君の給料
User yoshikyoto
Language Java (OpenJDK 1.7.0)
Score 100
Code Size 1112 Byte
Status AC
Exec Time 456 ms
Memory 24024 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 410 ms 23956 KB
example_1.txt AC 425 ms 24008 KB
example_2.txt AC 420 ms 23908 KB
example_3.txt AC 437 ms 23900 KB
maxrand_0.txt AC 442 ms 23948 KB
maxrand_1.txt AC 434 ms 23952 KB
maxrand_2.txt AC 451 ms 23828 KB
random_0.txt AC 423 ms 23968 KB
random_1.txt AC 456 ms 24024 KB
random_2.txt AC 421 ms 23768 KB
random_3.txt AC 436 ms 23956 KB
random_4.txt AC 429 ms 23924 KB
random_5.txt AC 421 ms 23952 KB
random_6.txt AC 416 ms 23948 KB
random_7.txt AC 423 ms 23920 KB
random_8.txt AC 417 ms 23876 KB
random_9.txt AC 410 ms 23952 KB
special_0.txt AC 414 ms 23948 KB