結果

問題 No.1418 Sum of Sum of Subtree Size
ユーザー y61mpnly61mpnl
提出日時 2021-03-06 00:37:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 2,140 ms
コンパイル使用メモリ 196,404 KB
実行使用メモリ 18,744 KB
最終ジャッジ日時 2024-04-16 12:34:14
合計ジャッジ時間 4,553 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,272 KB
testcase_01 AC 4 ms
6,144 KB
testcase_02 AC 4 ms
6,144 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 39 ms
9,540 KB
testcase_09 AC 19 ms
8,064 KB
testcase_10 AC 21 ms
7,880 KB
testcase_11 AC 12 ms
7,296 KB
testcase_12 AC 29 ms
9,132 KB
testcase_13 AC 36 ms
9,456 KB
testcase_14 AC 37 ms
9,616 KB
testcase_15 AC 27 ms
8,664 KB
testcase_16 AC 6 ms
6,400 KB
testcase_17 AC 6 ms
6,400 KB
testcase_18 AC 54 ms
10,832 KB
testcase_19 AC 11 ms
7,040 KB
testcase_20 AC 5 ms
6,272 KB
testcase_21 AC 27 ms
8,704 KB
testcase_22 AC 24 ms
8,412 KB
testcase_23 AC 5 ms
6,400 KB
testcase_24 AC 5 ms
6,400 KB
testcase_25 AC 5 ms
6,528 KB
testcase_26 AC 6 ms
6,272 KB
testcase_27 AC 4 ms
6,144 KB
testcase_28 AC 4 ms
6,272 KB
testcase_29 AC 6 ms
6,400 KB
testcase_30 AC 6 ms
6,400 KB
testcase_31 AC 5 ms
6,272 KB
testcase_32 AC 5 ms
6,400 KB
testcase_33 AC 14 ms
9,344 KB
testcase_34 WA -
testcase_35 AC 25 ms
11,512 KB
testcase_36 AC 7 ms
6,912 KB
testcase_37 AC 39 ms
11,016 KB
testcase_38 AC 35 ms
10,672 KB
testcase_39 AC 4 ms
6,272 KB
testcase_40 AC 4 ms
6,144 KB
testcase_41 AC 4 ms
6,144 KB
testcase_42 AC 3 ms
6,144 KB
testcase_43 AC 4 ms
6,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,b,e) for(int i=b;i<e;i++)
using ll = int_fast64_t;

std::vector<int> links[100000], visit;
int in[100000], out[100000], from[100000], cnt[100001];
bool used[100000];

void eular_tour(int v=0){
	if(used[v]) return;
	used[v] = true;
	in[v] = visit.size();
	visit.push_back(v);
	for(auto to: links[v]){
		if(!used[to]){
			from[to] = v;
			eular_tour(to);
		}
	}
	out[v] = visit.size();
}

int main(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n-1){
		int a, b;
		scanf("%d %d", &a, &b);
		links[a-1].push_back(b-1);
		links[b-1].push_back(a-1);
	}

	eular_tour();
	REP(i, 0, n) cnt[i] = out[i] - in[i];

	ll ans = 0;
	REP(i, 0, n){
		ans += n;
		for(auto x: links[i]){
			if(from[i]!=x) ans += cnt[x] * (n - cnt[x]);
			else ans += cnt[i] * (n - cnt[i]);
		}
	}
	printf("%ld\n", ans);
	return 0;
}
0