結果

問題 No.1817 Reversed Edges
ユーザー kokatsukokatsu
提出日時 2022-01-22 00:17:47
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 3,724 ms
コンパイル使用メモリ 199,960 KB
実行使用メモリ 16,232 KB
最終ジャッジ日時 2023-09-04 15:51:28
合計ジャッジ時間 6,647 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 121 ms
7,052 KB
testcase_08 AC 56 ms
5,144 KB
testcase_09 AC 115 ms
7,492 KB
testcase_10 AC 65 ms
5,492 KB
testcase_11 AC 85 ms
5,992 KB
testcase_12 AC 138 ms
8,796 KB
testcase_13 AC 137 ms
7,872 KB
testcase_14 AC 135 ms
7,680 KB
testcase_15 AC 138 ms
7,960 KB
testcase_16 AC 139 ms
8,544 KB
testcase_17 AC 139 ms
7,756 KB
testcase_18 AC 135 ms
7,644 KB
testcase_19 AC 140 ms
8,060 KB
testcase_20 AC 136 ms
7,984 KB
testcase_21 AC 134 ms
7,704 KB
testcase_22 AC 100 ms
7,516 KB
testcase_23 AC 100 ms
8,808 KB
testcase_24 AC 114 ms
16,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int N;
    readf("%d\n", N);

    auto list = new int[][](N);
    foreach (_; 0 .. N-1) {
        int A, B;
        readf("%d %d\n", A, B);

        --A, --B;
        list[A] ~= B, list[B] ~= A;
    }

    auto degs = new int[](N);

    int f(int now, int pre = -1) {
        int res;

        foreach (l; list[now]) {
            if (l == pre) continue;

            degs[l] = degs[now];
            if (l > now) ++degs[l];
            else --degs[l], ++res;

            res += f(l, now);
        }

        return res;
    }

    int s = f(0);
    foreach (d; degs) {
        writeln(s+d);
    }
}
0