結果

問題 No.2427 Tree Distance Two
ユーザー InTheBloomInTheBloom
提出日時 2023-08-18 22:17:36
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 478 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 4,025 ms
コンパイル使用メモリ 172,800 KB
実行使用メモリ 29,568 KB
最終ジャッジ日時 2024-05-06 04:28:35
合計ジャッジ時間 12,658 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 478 ms
27,392 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 450 ms
27,264 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 385 ms
22,528 KB
testcase_08 AC 397 ms
29,568 KB
testcase_09 AC 406 ms
28,032 KB
testcase_10 AC 405 ms
29,440 KB
testcase_11 AC 377 ms
27,904 KB
testcase_12 AC 402 ms
28,288 KB
testcase_13 AC 415 ms
27,904 KB
testcase_14 AC 337 ms
21,632 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 11 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 10 ms
5,376 KB
testcase_25 AC 98 ms
12,416 KB
testcase_26 AC 248 ms
20,864 KB
testcase_27 AC 190 ms
13,568 KB
testcase_28 AC 389 ms
27,008 KB
testcase_29 AC 344 ms
26,368 KB
testcase_30 AC 246 ms
19,584 KB
testcase_31 AC 148 ms
13,312 KB
testcase_32 AC 232 ms
19,200 KB
testcase_33 AC 215 ms
14,080 KB
testcase_34 AC 64 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    int N = readln.chomp.to!int;
    int[][] graph = new int[][](N, 0);
    foreach (i; 0..N-1) {
        int u, v; readln.read(u, v);
        u--, v--;
        graph[u] ~= v;
        graph[v] ~= u;
    }

    solve(N, graph);
}

void solve (int N, int[][] graph) {
    // スターグラフみたいなやつが来たら深さ2での探索うまくいかないんだよなぁってことで
    // 接続数を見ればいいんですね

    int[] ans = new int[](N);
    foreach (i; 0..N) {
        foreach (to; graph[i]) {
            ans[i] += graph[to].length-1;
        }
    }

    ans.each!writeln;
}

void read(T...)(string S, ref T args) {
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}
0