結果
問題 | No.2325 Skill Tree |
ユーザー | tenten |
提出日時 | 2023-08-09 13:30:56 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,264 ms / 3,000 ms |
コード長 | 2,875 bytes |
コンパイル時間 | 2,927 ms |
コンパイル使用メモリ | 92,536 KB |
実行使用メモリ | 81,128 KB |
最終ジャッジ日時 | 2024-11-15 09:12:37 |
合計ジャッジ時間 | 39,506 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
36,908 KB |
testcase_01 | AC | 52 ms
37,128 KB |
testcase_02 | AC | 52 ms
37,308 KB |
testcase_03 | AC | 51 ms
36,772 KB |
testcase_04 | AC | 52 ms
36,924 KB |
testcase_05 | AC | 51 ms
36,788 KB |
testcase_06 | AC | 51 ms
37,040 KB |
testcase_07 | AC | 378 ms
50,952 KB |
testcase_08 | AC | 415 ms
55,028 KB |
testcase_09 | AC | 447 ms
53,572 KB |
testcase_10 | AC | 562 ms
66,000 KB |
testcase_11 | AC | 562 ms
59,020 KB |
testcase_12 | AC | 849 ms
74,076 KB |
testcase_13 | AC | 874 ms
74,228 KB |
testcase_14 | AC | 864 ms
74,092 KB |
testcase_15 | AC | 989 ms
75,564 KB |
testcase_16 | AC | 943 ms
74,416 KB |
testcase_17 | AC | 834 ms
74,304 KB |
testcase_18 | AC | 847 ms
74,116 KB |
testcase_19 | AC | 918 ms
76,732 KB |
testcase_20 | AC | 927 ms
76,524 KB |
testcase_21 | AC | 905 ms
75,808 KB |
testcase_22 | AC | 842 ms
73,908 KB |
testcase_23 | AC | 920 ms
73,716 KB |
testcase_24 | AC | 939 ms
76,364 KB |
testcase_25 | AC | 945 ms
73,924 KB |
testcase_26 | AC | 865 ms
73,704 KB |
testcase_27 | AC | 1,253 ms
81,128 KB |
testcase_28 | AC | 1,183 ms
78,532 KB |
testcase_29 | AC | 1,207 ms
76,820 KB |
testcase_30 | AC | 1,168 ms
77,904 KB |
testcase_31 | AC | 1,264 ms
78,024 KB |
testcase_32 | AC | 1,076 ms
77,284 KB |
testcase_33 | AC | 1,092 ms
77,820 KB |
testcase_34 | AC | 1,083 ms
78,332 KB |
testcase_35 | AC | 1,161 ms
73,716 KB |
testcase_36 | AC | 1,091 ms
73,072 KB |
testcase_37 | AC | 1,198 ms
76,620 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); static int[] levels; static int[] needs; static TreeMap<Integer, Integer> counts = new TreeMap<>(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } levels = new int[n]; for (int i = 1; i < n; i++) { levels[i] = sc.nextInt(); graph.get(sc.nextInt() - 1).add(i); } needs = new int[n]; Arrays.fill(needs, -1); setNeeds(0, 0, 0); counts.put(0, 1); int current = 0; for (int x : counts.keySet()) { current += counts.get(x); counts.put(x, current); } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (q-- > 0) { int type = sc.nextInt(); int x = sc.nextInt(); if (type == 1) { sb.append(counts.floorEntry(x).getValue()).append("\n"); } else { sb.append(needs[x - 1]).append("\n"); } } System.out.print(sb); } static void setNeeds(int idx, int p, int v) { needs[idx] = Math.max(v, levels[idx]); counts.put(needs[idx], counts.getOrDefault(needs[idx], 0) + 1); for (int x : graph.get(idx)) { if (p != x) { setNeeds(x, idx, needs[idx]); } } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }