結果

問題 No.1477 Lamps on Graph
ユーザー phsplsphspls
提出日時 2022-10-05 23:37:47
言語 Rust
(1.77.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,705 bytes
コンパイル時間 11,861 ms
コンパイル使用メモリ 383,544 KB
実行使用メモリ 15,380 KB
最終ジャッジ日時 2024-06-10 13:29:47
合計ジャッジ時間 17,786 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 0 ms
6,812 KB
testcase_02 AC 1 ms
6,816 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 0 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 56 ms
7,168 KB
testcase_13 AC 57 ms
7,296 KB
testcase_14 AC 65 ms
7,936 KB
testcase_15 AC 24 ms
6,940 KB
testcase_16 AC 20 ms
6,944 KB
testcase_17 AC 24 ms
6,940 KB
testcase_18 AC 106 ms
10,436 KB
testcase_19 AC 59 ms
7,680 KB
testcase_20 AC 18 ms
6,940 KB
testcase_21 AC 92 ms
8,832 KB
testcase_22 AC 11 ms
6,944 KB
testcase_23 AC 33 ms
6,940 KB
testcase_24 AC 85 ms
9,472 KB
testcase_25 AC 24 ms
6,940 KB
testcase_26 AC 88 ms
10,240 KB
testcase_27 AC 28 ms
6,940 KB
testcase_28 AC 39 ms
6,944 KB
testcase_29 AC 42 ms
6,944 KB
testcase_30 AC 63 ms
6,944 KB
testcase_31 AC 34 ms
6,940 KB
testcase_32 AC 166 ms
15,380 KB
testcase_33 AC 124 ms
13,740 KB
testcase_34 AC 137 ms
11,008 KB
testcase_35 AC 112 ms
12,916 KB
testcase_36 AC 113 ms
12,672 KB
testcase_37 AC 80 ms
12,032 KB
testcase_38 AC 92 ms
12,288 KB
testcase_39 AC 111 ms
12,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `k`
  --> src/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

ソースコード

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