Submission #30949130
Source Code Expand
Copy
use std::collections::{BTreeSet, VecDeque};use proconio::{input, marker::Usize1};fn main() {input! {n: usize,m: usize,uv: [(Usize1, Usize1); m],};let mut rev = vec![vec![]; n];let mut edges = vec![BTreeSet::new(); n];for (u, v) in uv.iter().copied() {edges[u].insert(v);rev[v].push(u);}let mut deque = edges.iter().enumerate()
use std::collections::{BTreeSet, VecDeque}; use proconio::{input, marker::Usize1}; fn main() { input! { n: usize, m: usize, uv: [(Usize1, Usize1); m], }; let mut rev = vec![vec![]; n]; let mut edges = vec![BTreeSet::new(); n]; for (u, v) in uv.iter().copied() { edges[u].insert(v); rev[v].push(u); } let mut deque = edges .iter() .enumerate() .filter(|(_, e)| e.is_empty()) .map(|(v, _)| v) .collect::<VecDeque<usize>>(); let mut used = vec![false; n]; while let Some(v) = deque.pop_front() { if used[v] { continue; } used[v] = true; for u in rev[v].iter().copied() { edges[u].remove(&v); if edges[u].is_empty() { deque.push_back(u); } } } let ans = used.into_iter().filter(|&b| !b).count(); println!("{}", ans); }
Submission Info
Submission Time | |
---|---|
Task | F - Endless Walk |
User | bouzuya |
Language | Rust (1.42.0) |
Score | 500 |
Code Size | 953 Byte |
Status | AC |
Exec Time | 168 ms |
Memory | 45324 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_00.txt, example_01.txt |
All | example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, hand_18.txt, hand_19.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example_00.txt | AC | 6 ms | 2024 KB |
example_01.txt | AC | 2 ms | 2092 KB |
hand_00.txt | AC | 126 ms | 45284 KB |
hand_01.txt | AC | 132 ms | 45196 KB |
hand_02.txt | AC | 167 ms | 45324 KB |
hand_03.txt | AC | 147 ms | 45244 KB |
hand_04.txt | AC | 168 ms | 41220 KB |
hand_05.txt | AC | 135 ms | 41264 KB |
hand_06.txt | AC | 65 ms | 12360 KB |
hand_07.txt | AC | 62 ms | 12276 KB |
hand_08.txt | AC | 46 ms | 11784 KB |
hand_09.txt | AC | 103 ms | 28336 KB |
hand_10.txt | AC | 116 ms | 28268 KB |
hand_11.txt | AC | 115 ms | 34836 KB |
hand_12.txt | AC | 105 ms | 34412 KB |
hand_13.txt | AC | 155 ms | 38164 KB |
hand_14.txt | AC | 150 ms | 38144 KB |
hand_15.txt | AC | 16 ms | 13152 KB |
hand_16.txt | AC | 2 ms | 1900 KB |
hand_17.txt | AC | 1 ms | 2088 KB |
hand_18.txt | AC | 1 ms | 2128 KB |
hand_19.txt | AC | 82 ms | 40660 KB |
random_00.txt | AC | 51 ms | 12360 KB |
random_01.txt | AC | 56 ms | 12844 KB |
random_02.txt | AC | 55 ms | 14404 KB |
random_03.txt | AC | 62 ms | 15560 KB |
random_04.txt | AC | 85 ms | 20000 KB |
random_05.txt | AC | 45 ms | 12348 KB |
random_06.txt | AC | 50 ms | 13016 KB |
random_07.txt | AC | 53 ms | 14300 KB |
random_08.txt | AC | 61 ms | 15572 KB |
random_09.txt | AC | 78 ms | 19736 KB |
random_10.txt | AC | 46 ms | 12028 KB |
random_11.txt | AC | 48 ms | 13232 KB |
random_12.txt | AC | 53 ms | 14780 KB |
random_13.txt | AC | 59 ms | 17900 KB |
random_14.txt | AC | 137 ms | 35820 KB |