結果
| 問題 |
No.2337 Equidistant
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-02 23:40:23 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,701 bytes |
| コンパイル時間 | 13,142 ms |
| コンパイル使用メモリ | 396,588 KB |
| 実行使用メモリ | 26,968 KB |
| 最終ジャッジ日時 | 2024-12-28 23:57:29 |
| 合計ジャッジ時間 | 23,196 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 WA * 25 |
ソースコード
use std::collections::VecDeque;
fn main() {
let (n, q) = {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
(
iter.next().unwrap().parse::<usize>().unwrap(),
iter.next().unwrap().parse::<usize>().unwrap(),
)
};
let ab: Vec<_> = (0..(n - 1))
.map(|_| {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
(
iter.next().unwrap().parse::<usize>().unwrap() - 1,
iter.next().unwrap().parse::<usize>().unwrap() - 1,
)
})
.collect();
let st: Vec<_> = (0..q)
.map(|_| {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
(
iter.next().unwrap().parse::<usize>().unwrap() - 1,
iter.next().unwrap().parse::<usize>().unwrap() - 1,
)
})
.collect();
let mut graph = vec![vec![]; n];
for &(a, b) in &ab {
graph[a].push(b);
graph[b].push(a);
}
let mut dist = vec![n; n];
dist[0] = 0;
let mut queue = VecDeque::from(vec![0]);
while let Some(cur) = queue.pop_front() {
for &next in &graph[cur] {
if dist[cur] + 1 < dist[next] {
dist[next] = dist[cur] + 1;
queue.push_back(next);
}
}
}
for &(s, t) in &st {
println!("{}", (dist[s] % 2 == dist[t] % 2) as usize);
}
}