結果
問題 | No.1477 Lamps on Graph |
ユーザー | tenten |
提出日時 | 2022-08-05 11:48:02 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 790 ms / 2,000 ms |
コード長 | 2,393 bytes |
コンパイル時間 | 2,406 ms |
コンパイル使用メモリ | 79,776 KB |
実行使用メモリ | 62,480 KB |
最終ジャッジ日時 | 2024-09-15 07:34:48 |
合計ジャッジ時間 | 21,904 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
36,816 KB |
testcase_01 | AC | 52 ms
36,972 KB |
testcase_02 | AC | 52 ms
36,716 KB |
testcase_03 | AC | 53 ms
36,204 KB |
testcase_04 | AC | 52 ms
36,332 KB |
testcase_05 | AC | 51 ms
37,060 KB |
testcase_06 | AC | 52 ms
36,220 KB |
testcase_07 | AC | 51 ms
36,664 KB |
testcase_08 | AC | 52 ms
36,672 KB |
testcase_09 | AC | 51 ms
36,564 KB |
testcase_10 | AC | 52 ms
36,832 KB |
testcase_11 | AC | 52 ms
36,816 KB |
testcase_12 | AC | 497 ms
53,324 KB |
testcase_13 | AC | 603 ms
52,372 KB |
testcase_14 | AC | 580 ms
54,688 KB |
testcase_15 | AC | 353 ms
49,728 KB |
testcase_16 | AC | 331 ms
48,800 KB |
testcase_17 | AC | 322 ms
49,472 KB |
testcase_18 | AC | 549 ms
56,412 KB |
testcase_19 | AC | 482 ms
53,500 KB |
testcase_20 | AC | 295 ms
48,228 KB |
testcase_21 | AC | 486 ms
54,032 KB |
testcase_22 | AC | 220 ms
46,336 KB |
testcase_23 | AC | 405 ms
50,128 KB |
testcase_24 | AC | 616 ms
56,464 KB |
testcase_25 | AC | 346 ms
49,396 KB |
testcase_26 | AC | 603 ms
56,348 KB |
testcase_27 | AC | 390 ms
50,476 KB |
testcase_28 | AC | 448 ms
52,468 KB |
testcase_29 | AC | 424 ms
51,408 KB |
testcase_30 | AC | 384 ms
50,020 KB |
testcase_31 | AC | 349 ms
50,480 KB |
testcase_32 | AC | 752 ms
62,480 KB |
testcase_33 | AC | 685 ms
60,448 KB |
testcase_34 | AC | 535 ms
55,744 KB |
testcase_35 | AC | 790 ms
60,868 KB |
testcase_36 | AC | 747 ms
61,204 KB |
testcase_37 | AC | 709 ms
60,852 KB |
testcase_38 | AC | 735 ms
60,600 KB |
testcase_39 | AC | 774 ms
61,736 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); Path[] lights = new Path[n]; ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { lights[i] = new Path(i, sc.nextInt()); graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; if (lights[a].value > lights[b].value) { graph.get(b).add(a); } else if (lights[a].value < lights[b].value) { graph.get(a).add(b); } } Arrays.sort(lights); boolean[] isOn = new boolean[n]; int k = sc.nextInt(); while (k-- > 0) { isOn[sc.nextInt() - 1] = true; } StringBuilder sb = new StringBuilder(); int count = 0; for (Path x : lights) { if (!isOn[x.idx]) { continue; } sb.append(x.idx + 1).append("\n"); count++; for (int y : graph.get(x.idx)) { isOn[y] ^= true; } } System.out.println(count); System.out.print(sb); } static class Path implements Comparable<Path> { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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 String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }