結果
問題 |
No.2948 move move rotti
|
ユーザー |
![]() |
提出日時 | 2024-10-25 21:57:40 |
言語 | Rust (1.83.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,214 bytes |
コンパイル時間 | 13,502 ms |
コンパイル使用メモリ | 401,876 KB |
実行使用メモリ | 13,876 KB |
最終ジャッジ日時 | 2024-10-25 21:58:00 |
合計ジャッジ時間 | 19,604 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | TLE * 1 -- * 27 |
ソースコード
use proconio::marker::Usize1; use proconio::*; use std::collections::HashSet; fn main() { input! { n: usize, m: usize, k: usize, x: [Usize1; k], edges: [(Usize1, Usize1); m], } let mut graph = vec![vec![]; n]; for (a, b) in edges { graph[a].push(b); graph[b].push(a); } let mut v = vec![]; for i in 0..k { let mut seen = HashSet::new(); seen.insert(x[i]); v.push(dfs(x[i], &mut seen, &graph, &mut vec![(x[i], 1)])); } for i in v[0].iter() { let mut res = true; for j in 1..k { if !v[j].contains(&i) { res = false; break; } } if res { println!("{}", "Yes"); return; } } println!("{}", "No"); } fn dfs( v: usize, seen: &mut HashSet<usize>, graph: &Vec<Vec<usize>>, ret: &mut Vec<(usize, usize)>, ) -> Vec<(usize, usize)> { for &i in &graph[v] { if seen.contains(&i) { continue; } seen.insert(i); ret.push((i, seen.len())); dfs(i, seen, graph, ret); seen.remove(&i); } ret.clone() }