結果
| 問題 | No.3694 犬猿の仲 |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-09-22 06:02:05 |
| 言語 | Rust (1.97.1 + proconio + num + itertools + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 1,400 bytes |
| 記録 | |
| コンパイル時間 | 7,816 ms |
| コンパイル使用メモリ | 200,280 KB |
| 実行使用メモリ | 36,996 KB |
| 最終ジャッジ日時 | 2026-09-22 06:02:16 |
| 合計ジャッジ時間 | 4,936 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 WA * 2 |
ソースコード
#![allow(non_snake_case, unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
use proconio::{input, marker::Usize1, marker::Chars};
use itertools::Itertools;
#[allow(unused_macros)]
macro_rules! d {
( $( $x:expr ),* $(,)? ) => {
eprintln!(
concat!( $( stringify!($x), "={:?} " ),* ),
$( $x ),*
);
};
}
#[allow(dead_code)]
fn yn(b: bool) -> &'static str {
if b { "Yes" } else { "No" }
}
fn dfs(v: usize, adj: &HashMap<usize, Vec<usize>>, nodes: &mut Vec<i64>) -> bool {
let mut res = true;
if let Some(vs) = adj.get(&v) {
for &to in vs.iter() {
if to == v { continue }
if nodes[to] == -1 {
nodes[to] = nodes[v] ^ 1;
res &= dfs(to, adj, nodes);
} else if nodes[to] == nodes[v] {
return false;
}
}
}
res
}
fn main() {
input! {
N: usize,
M: usize,
}
let mut adj = HashMap::<usize, Vec<usize>>::new();
for _ in 0..M {
input! {
a: Usize1,
b: Usize1,
}
adj.entry(a).or_default().push(b);
}
let mut ans = true;
let mut nodes = vec![-1; N];
for i in 0..N {
if nodes[i] != -1 { continue }
nodes[i] = 0;
ans &= dfs(i, &adj, &mut nodes);
}
println!("{}", yn(ans));
}
norioc