結果

問題 No.1424 Ultrapalindrome
ユーザー StrorkisStrorkis
提出日時 2021-03-12 22:15:22
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,880 bytes
コンパイル時間 5,465 ms
コンパイル使用メモリ 145,792 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2024-04-22 13:17:02
合計ジャッジ時間 2,465 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 26 ms
12,032 KB
testcase_10 AC 23 ms
12,032 KB
testcase_11 AC 17 ms
9,088 KB
testcase_12 AC 22 ms
11,392 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 17 ms
9,728 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 14 ms
8,064 KB
testcase_17 AC 17 ms
9,216 KB
testcase_18 AC 10 ms
6,784 KB
testcase_19 AC 15 ms
8,960 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 13 ms
7,424 KB
testcase_22 AC 9 ms
5,504 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 21 ms
10,240 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 20 ms
16,000 KB
testcase_31 AC 21 ms
16,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn run<'a, F: FnMut() -> &'a str, W: std::io::Write>(scan: &mut F, writer: &mut W) {
    macro_rules! scan {
        ([$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($t)).collect::<Vec<_>>());
        (($($t:tt),*)) => (($(scan!($t)),*));
        (Usize1) => (scan!(usize) - 1);
        (Bytes) => (scan().as_bytes().to_vec());
        ($t:ty) => (scan().parse::<$t>().unwrap());
    }
    macro_rules! println {
        ($($arg:tt)*) => (writeln!(writer, $($arg)*).ok());
    }

    let n = scan!(usize);

    let mut graph = vec![vec![]; n];
    let mut degree = vec![0; n];
    for i in 0..(n - 1) {
        let (a, b) = scan!((Usize1, Usize1));
        graph[a].push((b, i));
        graph[b].push((a, i));
        degree[a] += 1;
        degree[b] += 1;
    }

    let mut deque = std::collections::VecDeque::new();
    let mut dist = vec![0; n];
    for (to, degree) in degree.into_iter().enumerate() {
        if degree == 1 {
            deque.push_back(to);
            dist[to] = 1;
        }
    }

    let mut used = vec![false; n];
    while let Some(from) = deque.pop_front() {
        for &(to, i) in &graph[from] {
            if used[i] {
                continue;
            } else if dist[to] == 0 {
                deque.push_back(to);
                dist[to] = dist[from] + 1;
            } else if dist[from] + 1 != dist[to] {
                println!("No");
                return;
            }
            used[i] = true;
        }
    }
    println!("Yes");
}

fn main() {
    let ref mut buf = Vec::new();
    std::io::Read::read_to_end(&mut std::io::stdin(), buf).ok();
    let mut scanner = unsafe {
        std::str::from_utf8_unchecked(buf).split_ascii_whitespace()
    };
    let ref mut scan = || scanner.next().unwrap();

    let stdout = std::io::stdout();
    let ref mut writer = std::io::BufWriter::new(stdout.lock());

    run(scan, writer);
}
0