結果

問題 No.1098 LCAs
ユーザー chocoruskchocorusk
提出日時 2020-06-27 05:32:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 517 ms / 2,000 ms
コード長 1,047 bytes
コンパイル時間 1,431 ms
コンパイル使用メモリ 128,560 KB
実行使用メモリ 29,124 KB
最終ジャッジ日時 2023-09-18 18:53:16
合計ジャッジ時間 9,680 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,236 KB
testcase_01 AC 4 ms
9,304 KB
testcase_02 AC 4 ms
9,104 KB
testcase_03 AC 4 ms
9,092 KB
testcase_04 AC 4 ms
9,212 KB
testcase_05 AC 4 ms
9,204 KB
testcase_06 AC 4 ms
9,100 KB
testcase_07 AC 4 ms
9,212 KB
testcase_08 AC 4 ms
9,140 KB
testcase_09 AC 5 ms
9,220 KB
testcase_10 AC 4 ms
9,208 KB
testcase_11 AC 4 ms
9,140 KB
testcase_12 AC 4 ms
9,152 KB
testcase_13 AC 6 ms
9,240 KB
testcase_14 AC 6 ms
9,240 KB
testcase_15 AC 6 ms
9,148 KB
testcase_16 AC 6 ms
9,260 KB
testcase_17 AC 6 ms
9,160 KB
testcase_18 AC 480 ms
17,732 KB
testcase_19 AC 474 ms
17,644 KB
testcase_20 AC 483 ms
17,696 KB
testcase_21 AC 488 ms
17,848 KB
testcase_22 AC 477 ms
17,648 KB
testcase_23 AC 411 ms
17,712 KB
testcase_24 AC 413 ms
17,780 KB
testcase_25 AC 394 ms
17,980 KB
testcase_26 AC 430 ms
17,764 KB
testcase_27 AC 422 ms
17,664 KB
testcase_28 AC 510 ms
28,060 KB
testcase_29 AC 517 ms
29,124 KB
testcase_30 AC 516 ms
28,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> g[200020];
ll cnt[200020];
ll ans[200020];
void dfs(int x, int p){
    cnt[x]=1;
    for(auto y:g[x]){
        if(y==p) continue;
        dfs(y, x);
        cnt[x]+=cnt[y];
        ans[x]-=cnt[y]*cnt[y];
    }
    ans[x]+=cnt[x]*cnt[x];
}
int main()
{
    int n; cin>>n;
    for(int i=0; i<n-1; i++){
        int x, y; cin>>x>>y; x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(0, -1);
    for(int i=0; i<n; i++) cout<<ans[i]<<endl;
    return 0;
}
0