結果

問題 No.1477 Lamps on Graph
ユーザー tonyu0tonyu0
提出日時 2021-04-16 21:59:07
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,510 bytes
コンパイル時間 14,437 ms
コンパイル使用メモリ 400,404 KB
実行使用メモリ 16,436 KB
最終ジャッジ日時 2024-07-03 01:44:05
合計ジャッジ時間 19,875 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 62 ms
8,820 KB
testcase_13 AC 64 ms
8,192 KB
testcase_14 AC 74 ms
9,876 KB
testcase_15 AC 25 ms
5,376 KB
testcase_16 AC 24 ms
5,456 KB
testcase_17 AC 27 ms
5,376 KB
testcase_18 AC 121 ms
10,524 KB
testcase_19 AC 65 ms
8,456 KB
testcase_20 AC 19 ms
5,376 KB
testcase_21 AC 101 ms
8,788 KB
testcase_22 AC 9 ms
5,376 KB
testcase_23 AC 32 ms
6,400 KB
testcase_24 AC 94 ms
11,076 KB
testcase_25 AC 24 ms
5,376 KB
testcase_26 AC 99 ms
11,308 KB
testcase_27 AC 28 ms
6,136 KB
testcase_28 AC 43 ms
7,832 KB
testcase_29 AC 43 ms
6,512 KB
testcase_30 AC 69 ms
5,844 KB
testcase_31 AC 39 ms
5,400 KB
testcase_32 AC 178 ms
16,436 KB
testcase_33 AC 135 ms
15,672 KB
testcase_34 AC 155 ms
16,384 KB
testcase_35 AC 139 ms
15,224 KB
testcase_36 AC 130 ms
15,280 KB
testcase_37 AC 97 ms
14,660 KB
testcase_38 AC 110 ms
14,860 KB
testcase_39 AC 132 ms
14,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();

    let mut ai = Vec::new();
    let mut a = Vec::new();
    for i in 0..n {
        let x: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        a.push(x);
        ai.push((x, i));
    }
    ai.sort();

    let mut g: Vec<Vec<usize>> = vec![Vec::new(); n];

    for _ in 0..m {
        let u: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let v: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        g[u].push(v);
        g[v].push(u);
    }

    let mut on: Vec<usize> = vec![0; n];
    let k: usize = itr.next().unwrap().parse().unwrap();
    for _ in 0..k {
        let b: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        on[b] = 1;
    }

    let mut ans = Vec::new();
    for &(_, i) in ai.iter() {
        if on[i] == 0 {
            continue;
        }
        ans.push(i + 1);
        on[i] = 0;
        for &ni in g[i].iter() {
            if a[i] < a[ni] {
                on[ni] ^= 1;
            }
        }
    }
    let mut ok = true;
    for i in 0..n {
        ok &= on[i] == 0;
    }
    if ok {
        println!("{}", ans.len());
        for &x in ans.iter() {
            println!("{}", x);
        }
    } else {
        println!("-1")
    }
}
0