結果

問題 No.1098 LCAs
ユーザー leaf_1415leaf_1415
提出日時 2020-06-26 21:40:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 421 ms / 2,000 ms
コード長 1,194 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 76,764 KB
実行使用メモリ 26,220 KB
最終ジャッジ日時 2023-09-18 03:36:54
合計ジャッジ時間 8,084 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,220 KB
testcase_01 AC 4 ms
9,196 KB
testcase_02 AC 4 ms
9,220 KB
testcase_03 AC 4 ms
9,284 KB
testcase_04 AC 4 ms
9,284 KB
testcase_05 AC 4 ms
9,152 KB
testcase_06 AC 4 ms
9,300 KB
testcase_07 AC 4 ms
9,180 KB
testcase_08 AC 5 ms
9,276 KB
testcase_09 AC 4 ms
9,152 KB
testcase_10 AC 4 ms
9,160 KB
testcase_11 AC 4 ms
9,132 KB
testcase_12 AC 5 ms
9,120 KB
testcase_13 AC 6 ms
9,168 KB
testcase_14 AC 6 ms
9,236 KB
testcase_15 AC 6 ms
9,220 KB
testcase_16 AC 6 ms
9,176 KB
testcase_17 AC 6 ms
9,216 KB
testcase_18 AC 378 ms
18,640 KB
testcase_19 AC 392 ms
18,696 KB
testcase_20 AC 379 ms
18,632 KB
testcase_21 AC 376 ms
18,756 KB
testcase_22 AC 374 ms
18,660 KB
testcase_23 AC 329 ms
18,544 KB
testcase_24 AC 346 ms
18,548 KB
testcase_25 AC 323 ms
18,496 KB
testcase_26 AC 346 ms
18,488 KB
testcase_27 AC 333 ms
18,500 KB
testcase_28 AC 417 ms
25,600 KB
testcase_29 AC 421 ms
26,220 KB
testcase_30 AC 421 ms
25,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
vector<llint> G[200005];
llint a[200005], b[200005];

void dfs(int v, int p)
{
	a[v] = 1;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		dfs(G[v][i], v);
		a[v] += a[G[v][i]];
	}
	b[v] = a[v] * a[v];
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		b[v] -= a[G[v][i]] * a[G[v][i]];
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint u, v;
	for(int i = 0; i < n-1; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	dfs(1, -1);
	
	for(int i = 1; i <= n; i++) cout << b[i] << endl;
	
	return 0;
}
0