結果

問題 No.1424 Ultrapalindrome
ユーザー StrorkisStrorkis
提出日時 2021-03-12 22:09:43
言語 Rust
(1.72.1)
結果
WA  
実行時間 -
コード長 1,755 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 153,088 KB
実行使用メモリ 13,348 KB
最終ジャッジ日時 2023-08-04 15:29:40
合計ジャッジ時間 2,532 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 19 ms
9,604 KB
testcase_10 AC 17 ms
9,644 KB
testcase_11 AC 13 ms
7,548 KB
testcase_12 AC 17 ms
9,208 KB
testcase_13 AC 5 ms
4,384 KB
testcase_14 AC 14 ms
7,936 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 11 ms
7,024 KB
testcase_17 AC 13 ms
7,632 KB
testcase_18 AC 8 ms
5,716 KB
testcase_19 AC 14 ms
7,520 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 10 ms
6,544 KB
testcase_22 AC 7 ms
4,836 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 16 ms
8,380 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 15 ms
12,308 KB
testcase_31 AC 17 ms
13,348 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 _ in 0..(n - 1) {
        let (a, b) = scan!((Usize1, Usize1));
        graph[a].push(b);
        graph[b].push(a);
        degree[a] += 1;
        degree[b] += 1;
    }

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

    while let Some(from) = deque.pop_front() {
        for &to in &graph[from] {
            if dist[to] == 0 {
                deque.push_back(to);
                dist[to] = dist[from] + 1;
            } else if (dist[from] - dist[to]).abs() != 1 {
                println!("No");
                return;
            }
        }
    }
    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