結果

問題 No.1477 Lamps on Graph
ユーザー tentententen
提出日時 2024-02-08 14:35:58
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,204 bytes
コンパイル時間 2,761 ms
コンパイル使用メモリ 91,500 KB
実行使用メモリ 80,852 KB
最終ジャッジ日時 2024-02-08 14:36:24
合計ジャッジ時間 25,077 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
55,000 KB
testcase_01 AC 87 ms
55,236 KB
testcase_02 AC 86 ms
53,064 KB
testcase_03 WA -
testcase_04 AC 86 ms
55,008 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 89 ms
55,136 KB
testcase_11 AC 87 ms
55,256 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 646 ms
76,840 KB
testcase_34 AC 645 ms
73,688 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

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<Integer> values = Stream.generate(sc::nextInt).limit(n).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) < values.get(b)) {
                graph.get(a).add(b);
            } else if (values.get(b) < values.get(a)) {
                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<>();
        IntStream.range(0, n).forEach(i -> {
            if (isOn[i]) {
                ans.add(i + 1);
                graph.get(i).stream().forEach(x -> isOn[x] ^= true);
            }
        });
        System.out.println(ans.size());
        System.out.println(ans.stream().map(x -> x.toString()).collect(Collectors.joining("\n")));
    }
}
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