結果
問題 | No.1023 Cyclic Tour |
ユーザー | akakimidori |
提出日時 | 2020-04-10 22:41:21 |
言語 | Rust (1.77.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,369 bytes |
コンパイル時間 | 1,231 ms |
コンパイル使用メモリ | 151,116 KB |
実行使用メモリ | 26,296 KB |
最終ジャッジ日時 | 2023-10-14 01:34:53 |
合計ジャッジ時間 | 6,342 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,348 KB |
testcase_01 | AC | 1 ms
4,352 KB |
testcase_02 | AC | 1 ms
4,352 KB |
testcase_03 | AC | 1 ms
4,352 KB |
testcase_04 | AC | 16 ms
7,268 KB |
testcase_05 | AC | 16 ms
7,296 KB |
testcase_06 | AC | 17 ms
7,872 KB |
testcase_07 | AC | 17 ms
7,600 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 37 ms
17,088 KB |
testcase_12 | AC | 29 ms
15,460 KB |
testcase_13 | AC | 26 ms
14,752 KB |
testcase_14 | WA | - |
testcase_15 | AC | 26 ms
14,960 KB |
testcase_16 | AC | 40 ms
18,064 KB |
testcase_17 | WA | - |
testcase_18 | AC | 39 ms
17,844 KB |
testcase_19 | AC | 42 ms
17,664 KB |
testcase_20 | AC | 63 ms
22,840 KB |
testcase_21 | AC | 61 ms
23,288 KB |
testcase_22 | AC | 58 ms
23,792 KB |
testcase_23 | AC | 56 ms
24,024 KB |
testcase_24 | AC | 50 ms
22,864 KB |
testcase_25 | WA | - |
testcase_26 | AC | 32 ms
13,104 KB |
testcase_27 | AC | 30 ms
12,692 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 66 ms
23,084 KB |
testcase_37 | AC | 37 ms
15,156 KB |
testcase_38 | WA | - |
testcase_39 | AC | 54 ms
23,068 KB |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 16 ms
7,332 KB |
testcase_45 | AC | 34 ms
16,996 KB |
testcase_46 | AC | 37 ms
14,668 KB |
testcase_47 | AC | 39 ms
17,624 KB |
testcase_48 | AC | 55 ms
26,196 KB |
testcase_49 | AC | 55 ms
25,468 KB |
testcase_50 | AC | 56 ms
26,264 KB |
testcase_51 | WA | - |
testcase_52 | WA | - |
ソースコード
//---------- begin union_find ---------- #[allow(dead_code)] mod union_find { pub struct UF { p: Vec<i32>, } impl UF { pub fn new(n: usize) -> UF { UF {p: vec![-1; n] } } pub fn init(&mut self) { for p in self.p.iter_mut() { *p = -1; } } pub fn root(&self, mut x: usize) -> usize { while self.p[x] >= 0 { x = self.p[x] as usize; } x } pub fn same(&self, x: usize, y: usize) -> bool { self.root(x) == self.root(y) } pub fn unite(&mut self, mut x: usize, mut y: usize) -> Option<(usize, usize)> { x = self.root(x); y = self.root(y); if x == y { return None; } if self.p[x] > self.p[y] { let s = x; x = y; y = s; } self.p[x] += self.p[y]; self.p[y] = x as i32; Some((x, y)) } pub fn get_size(&self, x: usize) -> usize { let r = self.root(x); (-self.p[r]) as usize } } } //---------- end union_find ---------- //https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // fn calc(g: &[Vec<usize>], src: usize) -> bool { let mut elem = vec![false; g.len()]; let mut q = std::collections::VecDeque::new(); elem[src] = true; q.push_back(src); while let Some(v) = q.pop_front() { for &u in g[v].iter() { if u == src { return true; } if !elem[u] { elem[u] = true; q.push_back(u); } } } false } fn run() { input! { n: usize, m: usize, e: [(usize1, usize1, usize); m], } let mut u = union_find::UF::new(n); for &(a, b, c) in e.iter() { if c == 1 { u.unite(a, b); } } let mut id = vec![n; n]; let mut k = 0; for i in 0..n { let r = u.root(i); if id[r] == n { id[r] = k; k += 1; } } let mut graph = vec![vec![]; k]; for &(a, b, c) in e.iter() { if c == 2 { let a = u.root(a); let b = u.root(b); graph[id[a]].push(id[b]); } } if calc(&graph, id[u.root(0)]) { println!("Yes"); return; } let mut graph = vec![vec![]; n]; let mut k = 0; for &(a, b, c) in e.iter() { if c == 1 { graph[a].push((b, k)); graph[b].push((a, k)); k += 1; } } let g = graph; let mut elem = vec![false; g.len()]; let mut q = std::collections::VecDeque::new(); elem[0] = true; q.push_back((0, k)); while let Some((v, p)) = q.pop_front() { for &(u, k) in g[v].iter() { if k != p && u == 0 { println!("Yes"); return; } if !elem[u] { elem[u] = true; q.push_back((u, k)); } } } println!("No"); } fn main() { run(); }