結果

問題 No.2427 Tree Distance Two
ユーザー Manuel1024Manuel1024
提出日時 2023-08-18 21:44:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 380 ms / 2,000 ms
コード長 476 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 73,116 KB
実行使用メモリ 21,708 KB
最終ジャッジ日時 2023-08-18 21:44:38
合計ジャッジ時間 8,305 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 346 ms
19,664 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 380 ms
19,596 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 308 ms
20,628 KB
testcase_08 AC 333 ms
21,708 KB
testcase_09 AC 319 ms
20,680 KB
testcase_10 AC 301 ms
21,060 KB
testcase_11 AC 293 ms
21,352 KB
testcase_12 AC 304 ms
20,116 KB
testcase_13 AC 343 ms
19,860 KB
testcase_14 AC 220 ms
19,520 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 7 ms
4,380 KB
testcase_21 AC 9 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 7 ms
4,376 KB
testcase_25 AC 78 ms
7,392 KB
testcase_26 AC 207 ms
13,404 KB
testcase_27 AC 135 ms
10,380 KB
testcase_28 AC 322 ms
18,532 KB
testcase_29 AC 288 ms
16,688 KB
testcase_30 AC 183 ms
12,992 KB
testcase_31 AC 132 ms
9,480 KB
testcase_32 AC 185 ms
12,908 KB
testcase_33 AC 162 ms
11,896 KB
testcase_34 AC 42 ms
5,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n; cin >> n;
    vector<vector<int>> G(n);
    for(int i = 0; i < n-1; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    for(int i = 0; i < n; i++){
        int ans = 0;
        for(auto &it: G[i]) ans += G[it].size();
        ans -= G[i].size();
        cout << ans << '\n';
    }
    return 0;
}
0