結果

問題 No.1098 LCAs
ユーザー face4face4
提出日時 2020-07-24 15:58:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 740 bytes
コンパイル時間 895 ms
コンパイル使用メモリ 72,728 KB
実行使用メモリ 43,500 KB
最終ジャッジ日時 2023-09-07 13:03:44
合計ジャッジ時間 10,750 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
12,844 KB
testcase_01 AC 6 ms
12,688 KB
testcase_02 AC 6 ms
12,700 KB
testcase_03 AC 6 ms
12,736 KB
testcase_04 AC 6 ms
12,796 KB
testcase_05 AC 6 ms
12,732 KB
testcase_06 AC 6 ms
12,808 KB
testcase_07 AC 6 ms
12,700 KB
testcase_08 AC 6 ms
12,704 KB
testcase_09 AC 6 ms
12,724 KB
testcase_10 AC 5 ms
12,712 KB
testcase_11 AC 6 ms
12,684 KB
testcase_12 AC 6 ms
12,684 KB
testcase_13 AC 8 ms
12,752 KB
testcase_14 AC 8 ms
12,968 KB
testcase_15 AC 8 ms
13,036 KB
testcase_16 AC 8 ms
12,800 KB
testcase_17 AC 8 ms
12,964 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 400 ms
21,912 KB
testcase_24 AC 403 ms
21,860 KB
testcase_25 AC 384 ms
21,812 KB
testcase_26 AC 413 ms
21,956 KB
testcase_27 AC 412 ms
21,812 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<int> v[200000], child, way[200000];

void dfs(int p, int x){
    child[x] = 1;
    for(int c : v[x]){
        if(c == p)  continue;
        dfs(x, c);
        way[x].push_back(c);
        child[x] += child[c];
    }
}

typedef long long ll;

int main(){
    int n;
    cin >> n;
    child.resize(n, 0);
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(-1, 0);
    for(int i = 0; i < n; i++){
        ll ans = 2*child[i]-1;
        for(int c : way[i]){
            ans += child[c]*(child[i]-1-child[c]);
        }
        cout << ans << endl;
    }
    return 0;
}
0