結果

問題 No.1477 Lamps on Graph
ユーザー StrorkisStrorkis
提出日時 2021-04-16 21:56:57
言語 Rust
(1.77.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,430 bytes
コンパイル時間 1,544 ms
コンパイル使用メモリ 151,172 KB
実行使用メモリ 16,252 KB
最終ジャッジ日時 2023-09-16 00:32:01
合計ジャッジ時間 5,168 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 30 ms
8,736 KB
testcase_13 AC 27 ms
8,084 KB
testcase_14 AC 37 ms
9,452 KB
testcase_15 AC 16 ms
5,472 KB
testcase_16 AC 13 ms
5,196 KB
testcase_17 AC 13 ms
4,444 KB
testcase_18 AC 34 ms
9,360 KB
testcase_19 AC 29 ms
8,556 KB
testcase_20 AC 10 ms
4,380 KB
testcase_21 AC 29 ms
8,084 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 21 ms
7,048 KB
testcase_24 AC 40 ms
9,972 KB
testcase_25 AC 13 ms
4,932 KB
testcase_26 AC 42 ms
10,416 KB
testcase_27 AC 19 ms
5,760 KB
testcase_28 AC 25 ms
7,856 KB
testcase_29 AC 22 ms
7,252 KB
testcase_30 AC 17 ms
5,364 KB
testcase_31 AC 14 ms
5,328 KB
testcase_32 AC 54 ms
16,252 KB
testcase_33 AC 52 ms
15,444 KB
testcase_34 AC 34 ms
16,252 KB
testcase_35 AC 63 ms
14,852 KB
testcase_36 AC 62 ms
14,872 KB
testcase_37 AC 58 ms
14,948 KB
testcase_38 AC 60 ms
14,944 KB
testcase_39 AC 62 ms
14,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Write;

fn main() {
    let ref mut buf = Vec::new();
    std::io::Read::read_to_end(&mut std::io::stdin(), buf).ok();
    let mut iter = std::str::from_utf8(buf).unwrap().split_whitespace();

    macro_rules! scan {
        ([$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($t)).collect::<Vec<_>>());
        (($($t:tt),*)) => (($(scan!($t)),*));
        (Usize1) => (scan!(usize) - 1);
        (Bytes) => (scan!(String).into_bytes());
        ($t:ty) => (iter.next().unwrap().parse::<$t>().unwrap());
    }

    let (n, m) = scan!((usize, usize));
    let a = scan!([u32; n]);

    let mut g = vec![vec![]; n];
    for _ in 0..m {
        let (u, v) = scan!((Usize1, Usize1));
        g[u].push(v);
        g[v].push(u);
    }

    let k = scan!(usize);

    let mut lit = vec![false; n];
    for _ in 0..k {
        let b = scan!(Usize1);
        lit[b] = true;
    }

    let mut ord = (0..n).collect::<Vec<_>>();
    ord.sort_by_key(|&i| a[i]);

    let mut ans = vec![];
    for from in ord {
        if !lit[from] {
            continue;
        }
        ans.push(from);
        for &to in &g[from] {
            if a[from] < a[to] {
                lit[to] ^= true;
            }
        }
    }

    let stdout = std::io::stdout();
    let mut writer = std::io::BufWriter::new(stdout.lock());

    writeln!(writer, "{}", ans.len()).ok();
    for ans in ans {
        writeln!(writer, "{}", ans + 1).ok();
    }
}
0