結果
問題 | No.1023 Cyclic Tour |
ユーザー | akakimidori |
提出日時 | 2020-04-10 22:47:58 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,731 bytes |
コンパイル時間 | 13,040 ms |
コンパイル使用メモリ | 395,892 KB |
実行使用メモリ | 16,480 KB |
最終ジャッジ日時 | 2024-09-15 23:01:17 |
合計ジャッジ時間 | 17,383 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | WA | - |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 13 ms
6,944 KB |
testcase_05 | AC | 14 ms
6,940 KB |
testcase_06 | AC | 15 ms
6,940 KB |
testcase_07 | AC | 14 ms
6,940 KB |
testcase_08 | AC | 24 ms
10,368 KB |
testcase_09 | AC | 23 ms
10,112 KB |
testcase_10 | AC | 22 ms
10,240 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 25 ms
11,520 KB |
testcase_15 | WA | - |
testcase_16 | AC | 39 ms
16,180 KB |
testcase_17 | AC | 40 ms
16,480 KB |
testcase_18 | AC | 38 ms
16,140 KB |
testcase_19 | AC | 38 ms
15,776 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 31 ms
11,324 KB |
testcase_26 | AC | 31 ms
11,528 KB |
testcase_27 | AC | 29 ms
11,036 KB |
testcase_28 | AC | 36 ms
14,872 KB |
testcase_29 | AC | 37 ms
15,504 KB |
testcase_30 | AC | 38 ms
14,944 KB |
testcase_31 | AC | 35 ms
13,788 KB |
testcase_32 | AC | 37 ms
14,732 KB |
testcase_33 | AC | 37 ms
14,568 KB |
testcase_34 | AC | 20 ms
9,196 KB |
testcase_35 | AC | 22 ms
9,480 KB |
testcase_36 | WA | - |
testcase_37 | AC | 35 ms
13,436 KB |
testcase_38 | AC | 39 ms
14,784 KB |
testcase_39 | WA | - |
testcase_40 | AC | 36 ms
13,516 KB |
testcase_41 | AC | 36 ms
13,464 KB |
testcase_42 | AC | 31 ms
11,620 KB |
testcase_43 | AC | 35 ms
14,728 KB |
testcase_44 | AC | 16 ms
6,944 KB |
testcase_45 | AC | 35 ms
13,824 KB |
testcase_46 | AC | 34 ms
13,824 KB |
testcase_47 | AC | 14 ms
6,940 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | AC | 26 ms
11,284 KB |
testcase_52 | AC | 27 ms
11,520 KB |
ソースコード
//---------- 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 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 { if u.unite(a, b).is_none() { println!("Yes"); return; } } } 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]); } } let mut elem = vec![false; k]; for i in 0..k { if elem[i] { continue; } let mut q = std::collections::VecDeque::new(); elem[i] = true; q.push_back(i); while let Some(v) = q.pop_front() { for &u in graph[v].iter() { if elem[u] { println!("Yes"); return; } elem[u] = true; q.push_back(u); } } } println!("No"); } fn main() { run(); }