結果

問題 No.2427 Tree Distance Two
ユーザー Manuel1024
提出日時 2023-08-18 21:44:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 476 bytes
コンパイル時間 1,320 ms
コンパイル使用メモリ 73,556 KB
実行使用メモリ 21,888 KB
最終ジャッジ日時 2024-11-28 06:21:30
合計ジャッジ時間 7,033 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

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