結果

問題 No.1103 Directed Length Sum
ユーザー kotatsugamekotatsugame
提出日時 2020-07-03 21:54:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 478 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 70,688 KB
実行使用メモリ 126,080 KB
最終ジャッジ日時 2023-10-17 02:03:02
合計ジャッジ時間 10,980 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
29,668 KB
testcase_01 AC 10 ms
29,668 KB
testcase_02 WA -
testcase_03 AC 483 ms
36,952 KB
testcase_04 AC 549 ms
41,484 KB
testcase_05 AC 967 ms
48,152 KB
testcase_06 AC 345 ms
38,308 KB
testcase_07 AC 76 ms
31,436 KB
testcase_08 AC 121 ms
32,368 KB
testcase_09 AC 52 ms
30,784 KB
testcase_10 AC 165 ms
35,368 KB
testcase_11 AC 599 ms
42,320 KB
testcase_12 AC 351 ms
38,372 KB
testcase_13 AC 181 ms
35,452 KB
testcase_14 AC 40 ms
30,504 KB
testcase_15 AC 274 ms
37,052 KB
testcase_16 AC 677 ms
43,536 KB
testcase_17 AC 713 ms
44,032 KB
testcase_18 AC 172 ms
35,348 KB
testcase_19 AC 632 ms
42,564 KB
testcase_20 AC 61 ms
31,016 KB
testcase_21 AC 113 ms
32,116 KB
testcase_22 AC 508 ms
40,692 KB
testcase_23 AC 302 ms
37,360 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:21:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   21 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
int N;
vector<int>G[1<<20];
long ans;
pair<int,long>dfs(int u,int p)
{
	int c=0;
	long t=0;
	for(int v:G[u])if(v!=p)
	{
		pair<int,long>q=dfs(v,u);
		c+=q.first;
		t+=q.second;
	}
	ans+=c+t;
	return make_pair(c+1,c+t);
}
int deg[1<<20];
main()
{
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int u,v;cin>>u>>v;
		u--,v--;
		G[u].push_back(v);
		deg[v]++;
	}
	int root=0;
	while(deg[root])root++;
	dfs(root,-1);
	cout<<ans<<endl;
}
0