結果
問題 | No.1477 Lamps on Graph |
ユーザー | tenten |
提出日時 | 2021-04-28 09:19:20 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 659 ms / 2,000 ms |
コード長 | 2,415 bytes |
コンパイル時間 | 4,599 ms |
コンパイル使用メモリ | 75,424 KB |
実行使用メモリ | 60,416 KB |
最終ジャッジ日時 | 2023-09-21 10:09:17 |
合計ジャッジ時間 | 21,037 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
34,032 KB |
testcase_01 | AC | 38 ms
34,052 KB |
testcase_02 | AC | 38 ms
33,676 KB |
testcase_03 | AC | 39 ms
33,756 KB |
testcase_04 | AC | 38 ms
34,024 KB |
testcase_05 | AC | 39 ms
34,152 KB |
testcase_06 | AC | 39 ms
33,716 KB |
testcase_07 | AC | 37 ms
33,756 KB |
testcase_08 | AC | 40 ms
34,068 KB |
testcase_09 | AC | 40 ms
34,132 KB |
testcase_10 | AC | 38 ms
34,120 KB |
testcase_11 | AC | 39 ms
34,132 KB |
testcase_12 | AC | 430 ms
51,460 KB |
testcase_13 | AC | 414 ms
50,692 KB |
testcase_14 | AC | 477 ms
52,572 KB |
testcase_15 | AC | 319 ms
46,952 KB |
testcase_16 | AC | 301 ms
45,076 KB |
testcase_17 | AC | 285 ms
45,224 KB |
testcase_18 | AC | 499 ms
54,808 KB |
testcase_19 | AC | 413 ms
51,364 KB |
testcase_20 | AC | 247 ms
44,508 KB |
testcase_21 | AC | 447 ms
51,868 KB |
testcase_22 | AC | 194 ms
44,980 KB |
testcase_23 | AC | 356 ms
48,264 KB |
testcase_24 | AC | 518 ms
55,520 KB |
testcase_25 | AC | 310 ms
45,936 KB |
testcase_26 | AC | 518 ms
54,788 KB |
testcase_27 | AC | 342 ms
48,472 KB |
testcase_28 | AC | 383 ms
49,024 KB |
testcase_29 | AC | 365 ms
49,144 KB |
testcase_30 | AC | 360 ms
46,932 KB |
testcase_31 | AC | 309 ms
46,140 KB |
testcase_32 | AC | 659 ms
60,416 KB |
testcase_33 | AC | 614 ms
59,976 KB |
testcase_34 | AC | 491 ms
54,660 KB |
testcase_35 | AC | 638 ms
59,304 KB |
testcase_36 | AC | 608 ms
59,956 KB |
testcase_37 | AC | 593 ms
57,152 KB |
testcase_38 | AC | 605 ms
58,640 KB |
testcase_39 | AC | 634 ms
58,432 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(); int[] values = new int[n]; Lamp[] lamps = new Lamp[n]; ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); lamps[i] = new Lamp(i, values[i]); graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; if (values[a] < values[b]) { graph.get(a).add(b); } if (values[b] < values[a]) { graph.get(b).add(a); } } int k = sc.nextInt(); boolean[] ons = new boolean[n]; for (int i = 0; i < k; i++) { ons[sc.nextInt() - 1] = true; } Arrays.sort(lamps); ArrayList<Integer> ans = new ArrayList<>(); for (Lamp x : lamps) { if (ons[x.idx]) { ans.add(x.idx + 1); for (int y : graph.get(x.idx)) { ons[y] ^= true; } } } StringBuilder sb = new StringBuilder(); sb.append(ans.size()).append("\n"); for (int x : ans) { sb.append(x).append("\n"); } System.out.print(sb); } static class Lamp implements Comparable<Lamp> { int idx; int value; public Lamp(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Lamp 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 String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }