結果

問題 No.763 Noelちゃんと木遊び
ユーザー nebukuro09nebukuro09
提出日時 2018-12-11 09:22:56
言語 D
(dmd 2.106.1)
結果
RE  
実行時間 -
コード長 1,077 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 108,368 KB
実行使用メモリ 14,484 KB
最終ジャッジ日時 2023-09-03 21:32:59
合計ジャッジ時間 7,513 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(17): Warning: statement is not reachable
Main.d(18): Warning: statement is not reachable
Main.d(19): Warning: statement is not reachable
Main.d(21): Warning: statement is not reachable
Main.d(22): Warning: statement is not reachable
Main.d(24): Warning: statement is not reachable
Main.d(42): Warning: statement is not reachable

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp.to!int;
    auto G = new int[][](N);
    foreach (_; 0..N-1) {
        auto s = readln.split.map!(to!int);
        G[s[0]-1] ~= s[1]-1;
        G[s[1]-1] ~= s[0]-1;
    }
    assert(0);

    int ans = 0;
    auto D = N.iota.map!(i => G[i].length.to!int).array;
    auto used = new bool[](N);

    DList!int queue;
    foreach (i; 0..N) if (D[i] == 1) queue.insertBack(i);

    while (!queue.empty) {
        int u = queue.front;
        queue.removeFront;

        if (used[u]) continue;
        used[u] = true;
        ans += 1;
        if (D[u] == 0) continue;

        int v = G[u].map!(v => !used[v]).front;
        used[v] = true;
        foreach (w; G[v]) {
            if (used[w]) continue;
            D[w] -= 1;
            if (D[w] <= 1) queue.insertBack(w);
        }
    }

    ans.writeln;
}
0