結果

問題 No.1477 Lamps on Graph
ユーザー tentententen
提出日時 2024-02-08 14:53:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 993 ms / 2,000 ms
コード長 2,591 bytes
コンパイル時間 2,885 ms
コンパイル使用メモリ 89,600 KB
実行使用メモリ 80,168 KB
最終ジャッジ日時 2024-02-08 14:53:35
合計ジャッジ時間 25,732 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
55,388 KB
testcase_01 AC 94 ms
55,384 KB
testcase_02 AC 94 ms
55,256 KB
testcase_03 AC 94 ms
55,264 KB
testcase_04 AC 94 ms
55,256 KB
testcase_05 AC 95 ms
55,252 KB
testcase_06 AC 96 ms
55,264 KB
testcase_07 AC 104 ms
53,436 KB
testcase_08 AC 94 ms
55,272 KB
testcase_09 AC 96 ms
55,264 KB
testcase_10 AC 94 ms
55,248 KB
testcase_11 AC 96 ms
55,268 KB
testcase_12 AC 673 ms
70,136 KB
testcase_13 AC 649 ms
70,168 KB
testcase_14 AC 773 ms
73,476 KB
testcase_15 AC 445 ms
65,720 KB
testcase_16 AC 426 ms
65,884 KB
testcase_17 AC 421 ms
65,820 KB
testcase_18 AC 806 ms
76,600 KB
testcase_19 AC 636 ms
69,984 KB
testcase_20 AC 393 ms
62,928 KB
testcase_21 AC 725 ms
73,352 KB
testcase_22 AC 288 ms
62,448 KB
testcase_23 AC 480 ms
66,484 KB
testcase_24 AC 796 ms
76,868 KB
testcase_25 AC 432 ms
65,772 KB
testcase_26 AC 852 ms
76,996 KB
testcase_27 AC 470 ms
65,752 KB
testcase_28 AC 578 ms
68,664 KB
testcase_29 AC 534 ms
68,028 KB
testcase_30 AC 520 ms
66,300 KB
testcase_31 AC 456 ms
64,884 KB
testcase_32 AC 927 ms
79,224 KB
testcase_33 AC 850 ms
77,248 KB
testcase_34 AC 697 ms
73,592 KB
testcase_35 AC 993 ms
80,168 KB
testcase_36 AC 949 ms
77,188 KB
testcase_37 AC 893 ms
78,376 KB
testcase_38 AC 991 ms
79,904 KB
testcase_39 AC 951 ms
77,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Unit> values = IntStream.range(0, n).mapToObj(i -> new Unit(i, sc.nextInt())).toList();
        List<List<Integer>> graph = IntStream.range(0, n).mapToObj(i -> new ArrayList<Integer>()).collect(Collectors.toList());
        IntStream.range(0, m).forEach(i -> {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            if (values.get(a).value < values.get(b).value) {
                graph.get(a).add(b);
            } else if (values.get(b).value < values.get(a).value) {
                graph.get(b).add(a);
            }
        });
        boolean[] isOn = new boolean[n];
        IntStream.range(0, sc.nextInt()).forEach(i -> {
            isOn[sc.nextInt() - 1] = true;
        });
        List<Integer> ans = new ArrayList<>();
        values.stream().sorted().forEach(x -> {
            if (isOn[x.idx]) {
                ans.add(x.idx + 1);
                graph.get(x.idx).stream().forEach(y -> isOn[y] ^= true);
            }
        });
        System.out.println(ans.size());
        System.out.println(ans.stream().map(x -> x.toString()).collect(Collectors.joining("\n")));
    }
    
    static class Unit implements Comparable<Unit> {
        int idx;
        int value;
        
        public Unit(int idx, int value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Unit another) {
            return value - another.value;
        }
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0