結果

問題 No.2427 Tree Distance Two
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-08-18 21:27:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 690 ms / 2,000 ms
コード長 450 bytes
コンパイル時間 2,015 ms
コンパイル使用メモリ 203,632 KB
実行使用メモリ 21,888 KB
最終ジャッジ日時 2024-05-06 03:17:50
合計ジャッジ時間 14,317 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 690 ms
19,968 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 683 ms
19,968 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 626 ms
20,804 KB
testcase_08 AC 654 ms
21,888 KB
testcase_09 AC 643 ms
20,864 KB
testcase_10 AC 632 ms
21,248 KB
testcase_11 AC 633 ms
21,484 KB
testcase_12 AC 668 ms
20,408 KB
testcase_13 AC 657 ms
20,224 KB
testcase_14 AC 542 ms
19,584 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 16 ms
5,376 KB
testcase_21 AC 18 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 17 ms
5,376 KB
testcase_25 AC 156 ms
7,552 KB
testcase_26 AC 402 ms
13,440 KB
testcase_27 AC 273 ms
10,624 KB
testcase_28 AC 617 ms
18,688 KB
testcase_29 AC 540 ms
16,896 KB
testcase_30 AC 382 ms
13,312 KB
testcase_31 AC 241 ms
9,728 KB
testcase_32 AC 375 ms
13,184 KB
testcase_33 AC 320 ms
12,032 KB
testcase_34 AC 94 ms
6,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){

    int N, u, v;
    cin >> N;
    vector<vector<int>> E(N);
    for (int i=0; i<N-1; i++){
        cin >> u >> v;
        u--; v--;
        E[u].push_back(v);
        E[v].push_back(u);
    }

    for (int i=0; i<N; i++){
        int ans=0;
        for (auto x : E[i]){
            ans += E[x].size()-1;
        }
        cout << ans << endl;
    }

    return 0;
}
0