結果
問題 | No.2325 Skill Tree |
ユーザー | tenten |
提出日時 | 2023-05-30 14:10:56 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,286 ms / 3,000 ms |
コード長 | 3,108 bytes |
コンパイル時間 | 2,467 ms |
コンパイル使用メモリ | 90,728 KB |
実行使用メモリ | 95,164 KB |
最終ジャッジ日時 | 2023-08-28 00:35:15 |
合計ジャッジ時間 | 34,792 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
49,896 KB |
testcase_01 | AC | 43 ms
49,600 KB |
testcase_02 | AC | 44 ms
49,984 KB |
testcase_03 | AC | 43 ms
49,600 KB |
testcase_04 | AC | 42 ms
49,800 KB |
testcase_05 | AC | 43 ms
49,900 KB |
testcase_06 | AC | 44 ms
49,628 KB |
testcase_07 | AC | 366 ms
61,424 KB |
testcase_08 | AC | 414 ms
65,640 KB |
testcase_09 | AC | 407 ms
63,456 KB |
testcase_10 | AC | 556 ms
75,936 KB |
testcase_11 | AC | 510 ms
73,868 KB |
testcase_12 | AC | 906 ms
86,200 KB |
testcase_13 | AC | 993 ms
90,176 KB |
testcase_14 | AC | 919 ms
86,264 KB |
testcase_15 | AC | 990 ms
89,844 KB |
testcase_16 | AC | 807 ms
91,604 KB |
testcase_17 | AC | 877 ms
90,508 KB |
testcase_18 | AC | 811 ms
86,272 KB |
testcase_19 | AC | 788 ms
92,528 KB |
testcase_20 | AC | 876 ms
86,820 KB |
testcase_21 | AC | 864 ms
89,040 KB |
testcase_22 | AC | 985 ms
88,300 KB |
testcase_23 | AC | 862 ms
84,156 KB |
testcase_24 | AC | 825 ms
84,272 KB |
testcase_25 | AC | 937 ms
94,116 KB |
testcase_26 | AC | 975 ms
89,204 KB |
testcase_27 | AC | 1,174 ms
94,996 KB |
testcase_28 | AC | 1,158 ms
94,152 KB |
testcase_29 | AC | 1,286 ms
95,164 KB |
testcase_30 | AC | 1,102 ms
93,456 KB |
testcase_31 | AC | 1,185 ms
93,796 KB |
testcase_32 | AC | 1,007 ms
82,364 KB |
testcase_33 | AC | 1,026 ms
92,488 KB |
testcase_34 | AC | 993 ms
93,160 KB |
testcase_35 | AC | 1,066 ms
82,204 KB |
testcase_36 | AC | 1,097 ms
87,076 KB |
testcase_37 | AC | 1,192 ms
81,336 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } int[] levels = new int[n]; for (int i = 1; i < n; i++) { levels[i] = sc.nextInt(); int x = sc.nextInt() - 1; graph.get(x).add(i); } int[] needs = new int[n]; int[] tmp = new int[n]; Arrays.fill(needs, -1); Arrays.fill(tmp, Integer.MAX_VALUE); ArrayDeque<Path> queue = new ArrayDeque<>(); queue.add(new Path(0, 0)); while (queue.size() > 0) { Path p = queue.poll(); p.value = Math.max(p.value, levels[p.idx]); needs[p.idx] = p.value; tmp[p.idx] = p.value; for (int x : graph.get(p.idx)) { queue.add(new Path(x, p.value)); } } TreeMap<Integer, Integer> counts = new TreeMap<>(); Arrays.sort(tmp); for (int i = 0; i < n; i++) { counts.put(tmp[i], i + 1); } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (q-- > 0) { int type = sc.nextInt(); int v = sc.nextInt(); if (type == 1) { sb.append(counts.floorEntry(v).getValue()).append("\n"); } else { sb.append(needs[v - 1]).append("\n"); } } System.out.print(sb); } static class Path { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } } } 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(); } }