結果

問題 No.1477 Lamps on Graph
ユーザー phsplsphspls
提出日時 2022-10-05 23:37:47
言語 Rust
(1.77.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,705 bytes
コンパイル時間 7,197 ms
コンパイル使用メモリ 149,400 KB
実行使用メモリ 15,328 KB
最終ジャッジ日時 2023-08-30 13:28:44
合計ジャッジ時間 10,685 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,388 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 68 ms
7,172 KB
testcase_13 AC 72 ms
7,188 KB
testcase_14 AC 83 ms
7,952 KB
testcase_15 AC 30 ms
4,384 KB
testcase_16 AC 23 ms
5,068 KB
testcase_17 AC 27 ms
4,604 KB
testcase_18 AC 117 ms
10,356 KB
testcase_19 AC 69 ms
7,672 KB
testcase_20 AC 22 ms
4,384 KB
testcase_21 AC 103 ms
8,756 KB
testcase_22 AC 12 ms
4,384 KB
testcase_23 AC 39 ms
4,632 KB
testcase_24 AC 104 ms
9,620 KB
testcase_25 AC 29 ms
4,384 KB
testcase_26 AC 106 ms
10,088 KB
testcase_27 AC 35 ms
4,820 KB
testcase_28 AC 48 ms
6,636 KB
testcase_29 AC 49 ms
5,704 KB
testcase_30 AC 68 ms
6,040 KB
testcase_31 AC 40 ms
5,292 KB
testcase_32 AC 182 ms
15,328 KB
testcase_33 AC 136 ms
13,768 KB
testcase_34 AC 155 ms
11,028 KB
testcase_35 AC 140 ms
12,880 KB
testcase_36 AC 136 ms
12,892 KB
testcase_37 AC 101 ms
12,024 KB
testcase_38 AC 117 ms
12,288 KB
testcase_39 AC 137 ms
12,540 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `k`
  --> Main.rs:27:9
   |
27 |     let k: usize = k.trim().parse().unwrap();
   |         ^ help: if this is intentional, prefix it with an underscore: `_k`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut paths = vec![vec![]; n];
    for _ in 0..m {
        let mut uv = String::new();
        std::io::stdin().read_line(&mut uv).ok();
        let uv: Vec<usize> = uv.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let u = uv[0]-1;
        let v = uv[1]-1;
        if a[u] < a[v] {
            paths[u].push(v);
        }
        if a[v] < a[u] {
            paths[v].push(u);
        }
    }
    let mut k = String::new();
    std::io::stdin().read_line(&mut k).ok();
    let k: usize = k.trim().parse().unwrap();
    let mut b = String::new();
    std::io::stdin().read_line(&mut b).ok();
    let b: Vec<usize> = b.trim().split_whitespace().map(|s| s.parse::<usize>().unwrap()-1).collect();

    let mut lamps = vec![0usize; n];
    for &v in b.iter() { lamps[v] = 1; }
    let mut a = (0..n).map(|i| (a[i], i)).collect::<Vec<_>>();
    a.sort();
    let mut result = vec![];
    for &(_, u) in a.iter() {
        if lamps[u] == 0 { continue; }
        result.push(u);
        lamps[u] = 0;
        for &v in paths[u].iter() {
            lamps[v] = 1 - lamps[v];
        }
    }
    if lamps.iter().sum::<usize>() == 0 {
        println!("{}", result.len());
        for &v in result.iter() {
            println!("{}", v+1);
        }
    } else {
        println!("-1");
    }
}
0