結果

問題 No.1418 Sum of Sum of Subtree Size
ユーザー kotatsugamekotatsugame
提出日時 2021-03-10 23:57:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 410 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 69,876 KB
実行使用メモリ 17,536 KB
最終ジャッジ日時 2024-04-20 17:52:40
合計ジャッジ時間 3,487 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,656 KB
testcase_01 AC 3 ms
6,528 KB
testcase_02 AC 3 ms
6,528 KB
testcase_03 AC 80 ms
9,600 KB
testcase_04 AC 77 ms
9,728 KB
testcase_05 AC 79 ms
9,728 KB
testcase_06 AC 76 ms
9,728 KB
testcase_07 AC 77 ms
9,856 KB
testcase_08 AC 52 ms
8,832 KB
testcase_09 AC 26 ms
7,680 KB
testcase_10 AC 28 ms
7,680 KB
testcase_11 AC 17 ms
7,296 KB
testcase_12 AC 41 ms
8,192 KB
testcase_13 AC 49 ms
8,576 KB
testcase_14 AC 51 ms
8,704 KB
testcase_15 AC 37 ms
8,192 KB
testcase_16 AC 7 ms
6,912 KB
testcase_17 AC 8 ms
6,656 KB
testcase_18 AC 72 ms
9,344 KB
testcase_19 AC 15 ms
7,040 KB
testcase_20 AC 5 ms
6,656 KB
testcase_21 AC 37 ms
8,064 KB
testcase_22 AC 33 ms
7,936 KB
testcase_23 AC 6 ms
6,656 KB
testcase_24 AC 5 ms
6,528 KB
testcase_25 AC 4 ms
6,656 KB
testcase_26 AC 5 ms
6,528 KB
testcase_27 AC 3 ms
6,528 KB
testcase_28 AC 4 ms
6,528 KB
testcase_29 AC 6 ms
6,656 KB
testcase_30 AC 6 ms
6,656 KB
testcase_31 AC 4 ms
6,784 KB
testcase_32 AC 5 ms
6,528 KB
testcase_33 AC 19 ms
8,960 KB
testcase_34 AC 75 ms
17,536 KB
testcase_35 AC 34 ms
11,264 KB
testcase_36 AC 10 ms
6,912 KB
testcase_37 AC 52 ms
9,676 KB
testcase_38 AC 47 ms
9,436 KB
testcase_39 AC 3 ms
6,528 KB
testcase_40 AC 4 ms
6,528 KB
testcase_41 AC 3 ms
6,528 KB
testcase_42 AC 3 ms
6,400 KB
testcase_43 AC 3 ms
6,528 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:20:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
int N;
vector<int>G[1<<17];
long ans;
int dfs(int u,int p)
{
	ans+=N;
	int ch=0;
	for(int v:G[u])if(v!=p)
	{
		long c=dfs(v,u);
		ans+=c*(N-c);
		ch+=c;
	}
	ans+=(long)(ch+1)*(N-ch-1);
	return ch+1;
}
main()
{
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,-1);
	cout<<ans<<endl;
}
0