結果
問題 | No.1477 Lamps on Graph |
ユーザー | tenten |
提出日時 | 2022-08-05 11:48:02 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 739 ms / 2,000 ms |
コード長 | 2,393 bytes |
コンパイル時間 | 3,236 ms |
コンパイル使用メモリ | 74,924 KB |
実行使用メモリ | 73,396 KB |
最終ジャッジ日時 | 2023-10-13 10:29:48 |
合計ジャッジ時間 | 23,149 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
49,888 KB |
testcase_01 | AC | 44 ms
49,568 KB |
testcase_02 | AC | 44 ms
49,604 KB |
testcase_03 | AC | 46 ms
49,696 KB |
testcase_04 | AC | 44 ms
49,900 KB |
testcase_05 | AC | 45 ms
49,640 KB |
testcase_06 | AC | 44 ms
49,488 KB |
testcase_07 | AC | 44 ms
49,496 KB |
testcase_08 | AC | 45 ms
49,592 KB |
testcase_09 | AC | 45 ms
49,720 KB |
testcase_10 | AC | 46 ms
49,796 KB |
testcase_11 | AC | 45 ms
49,488 KB |
testcase_12 | AC | 500 ms
63,256 KB |
testcase_13 | AC | 461 ms
49,488 KB |
testcase_14 | AC | 556 ms
51,912 KB |
testcase_15 | AC | 345 ms
45,312 KB |
testcase_16 | AC | 295 ms
45,584 KB |
testcase_17 | AC | 303 ms
45,760 KB |
testcase_18 | AC | 545 ms
53,296 KB |
testcase_19 | AC | 468 ms
49,332 KB |
testcase_20 | AC | 269 ms
45,200 KB |
testcase_21 | AC | 460 ms
51,196 KB |
testcase_22 | AC | 195 ms
43,448 KB |
testcase_23 | AC | 390 ms
46,684 KB |
testcase_24 | AC | 590 ms
54,256 KB |
testcase_25 | AC | 347 ms
46,200 KB |
testcase_26 | AC | 599 ms
54,196 KB |
testcase_27 | AC | 364 ms
47,228 KB |
testcase_28 | AC | 433 ms
49,260 KB |
testcase_29 | AC | 408 ms
48,728 KB |
testcase_30 | AC | 362 ms
47,096 KB |
testcase_31 | AC | 323 ms
47,300 KB |
testcase_32 | AC | 708 ms
59,868 KB |
testcase_33 | AC | 690 ms
73,396 KB |
testcase_34 | AC | 465 ms
66,712 KB |
testcase_35 | AC | 738 ms
59,276 KB |
testcase_36 | AC | 719 ms
59,780 KB |
testcase_37 | AC | 669 ms
58,308 KB |
testcase_38 | AC | 690 ms
58,852 KB |
testcase_39 | AC | 739 ms
59,012 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(); } }