結果

問題 No.1477 Lamps on Graph
ユーザー tonyu0tonyu0
提出日時 2021-04-16 22:01:05
言語 Rust
(1.77.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 1,506 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 145,924 KB
実行使用メモリ 18,320 KB
最終ジャッジ日時 2023-09-16 00:40:50
合計ジャッジ時間 5,467 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 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 0 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,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 55 ms
9,548 KB
testcase_13 AC 61 ms
8,972 KB
testcase_14 AC 66 ms
10,168 KB
testcase_15 AC 22 ms
5,724 KB
testcase_16 AC 21 ms
5,868 KB
testcase_17 AC 25 ms
4,992 KB
testcase_18 AC 117 ms
11,088 KB
testcase_19 AC 62 ms
9,464 KB
testcase_20 AC 18 ms
4,376 KB
testcase_21 AC 102 ms
9,672 KB
testcase_22 AC 8 ms
4,376 KB
testcase_23 AC 31 ms
7,312 KB
testcase_24 AC 88 ms
11,024 KB
testcase_25 AC 23 ms
5,388 KB
testcase_26 AC 95 ms
11,616 KB
testcase_27 AC 26 ms
6,368 KB
testcase_28 AC 38 ms
8,724 KB
testcase_29 AC 41 ms
7,860 KB
testcase_30 AC 68 ms
6,172 KB
testcase_31 AC 39 ms
5,832 KB
testcase_32 AC 174 ms
18,320 KB
testcase_33 AC 129 ms
17,568 KB
testcase_34 AC 151 ms
18,320 KB
testcase_35 AC 127 ms
16,780 KB
testcase_36 AC 120 ms
16,784 KB
testcase_37 AC 85 ms
16,520 KB
testcase_38 AC 101 ms
16,720 KB
testcase_39 AC 119 ms
16,732 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();
        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