結果
問題 | No.1477 Lamps on Graph |
ユーザー | fukafukatani |
提出日時 | 2021-04-16 23:48:21 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 175 ms / 2,000 ms |
コード長 | 2,445 bytes |
コンパイル時間 | 17,130 ms |
コンパイル使用メモリ | 378,092 KB |
実行使用メモリ | 19,732 KB |
最終ジャッジ日時 | 2024-07-03 04:52:44 |
合計ジャッジ時間 | 18,340 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 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 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 72 ms
9,840 KB |
testcase_13 | AC | 72 ms
8,916 KB |
testcase_14 | AC | 88 ms
10,904 KB |
testcase_15 | AC | 33 ms
6,016 KB |
testcase_16 | AC | 22 ms
6,036 KB |
testcase_17 | AC | 25 ms
5,376 KB |
testcase_18 | AC | 109 ms
9,944 KB |
testcase_19 | AC | 68 ms
9,284 KB |
testcase_20 | AC | 23 ms
5,376 KB |
testcase_21 | AC | 98 ms
8,760 KB |
testcase_22 | AC | 14 ms
5,376 KB |
testcase_23 | AC | 43 ms
6,784 KB |
testcase_24 | AC | 109 ms
12,032 KB |
testcase_25 | AC | 32 ms
5,376 KB |
testcase_26 | AC | 104 ms
12,652 KB |
testcase_27 | AC | 37 ms
6,728 KB |
testcase_28 | AC | 51 ms
9,076 KB |
testcase_29 | AC | 50 ms
7,288 KB |
testcase_30 | AC | 63 ms
5,904 KB |
testcase_31 | AC | 36 ms
5,668 KB |
testcase_32 | AC | 175 ms
19,732 KB |
testcase_33 | AC | 131 ms
17,580 KB |
testcase_34 | AC | 156 ms
9,528 KB |
testcase_35 | AC | 143 ms
16,388 KB |
testcase_36 | AC | 139 ms
16,912 KB |
testcase_37 | AC | 107 ms
16,788 KB |
testcase_38 | AC | 121 ms
17,040 KB |
testcase_39 | AC | 170 ms
16,908 KB |
コンパイルメッセージ
warning: unused variable: `i` --> src/main.rs:24:9 | 24 | for i in 0..m { | ^ help: if this is intentional, prefix it with an underscore: `_i` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `k` --> src/main.rs:35:9 | 35 | let k = read::<usize>(); | ^ help: if this is intentional, prefix it with an underscore: `_k`
ソースコード
#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let v = read_vec::<usize>(); let (n, m) = (v[0], v[1]); let a = read_vec::<i64>(); let mut edges = vec![]; let mut g = vec![vec![]; n]; for i in 0..m { let v = read_vec::<usize>(); let (u, v) = (v[0] - 1, v[1] - 1); if a[u] < a[v] { edges.push((u, v)); g[u].push(v); } else if a[u] > a[v] { edges.push((v, u)); g[v].push(u); } } let k = read::<usize>(); let v = read_vec::<usize>(); let mut light = vec![false; n]; for i in v { light[i - 1] = true; } let indexes = topological_sort(&edges, n).unwrap(); let mut answers = vec![]; for i in indexes { if light[i] { for &to in g[i].iter() { light[to] = !light[to]; } answers.push(i); } } println!("{}", answers.len()); for ans in answers { println!("{}", ans + 1); } } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn topological_sort(edges: &Vec<(usize, usize)>, v: usize) -> Option<Vec<usize>> { let mut h = vec![0; v]; let mut g = vec![Vec::new(); v]; for &(s, t) in edges { g[s].push(t); h[t] += 1; } let mut st: std::collections::VecDeque<usize> = std::collections::VecDeque::new(); for i in 0..v { if h[i] == 0 { st.push_back(i); } } let mut sorted_indexes = Vec::new(); while !st.is_empty() { let i = st.pop_back().unwrap(); sorted_indexes.push(i); for &j in g[i].iter() { h[j] -= 1; if h[j] == 0 { st.push_back(j); } } } if sorted_indexes.len() == v { Some(sorted_indexes) } else { None } }