結果

問題 No.1098 LCAs
ユーザー kotatsugamekotatsugame
提出日時 2020-06-26 21:49:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 520 ms / 2,000 ms
コード長 474 bytes
コンパイル時間 602 ms
コンパイル使用メモリ 73,512 KB
実行使用メモリ 40,556 KB
最終ジャッジ日時 2023-09-18 04:07:39
合計ジャッジ時間 8,500 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,496 KB
testcase_01 AC 4 ms
9,488 KB
testcase_02 AC 4 ms
9,488 KB
testcase_03 AC 4 ms
9,472 KB
testcase_04 AC 3 ms
9,484 KB
testcase_05 AC 3 ms
9,500 KB
testcase_06 AC 3 ms
9,540 KB
testcase_07 AC 3 ms
9,812 KB
testcase_08 AC 4 ms
9,668 KB
testcase_09 AC 3 ms
9,500 KB
testcase_10 AC 4 ms
9,492 KB
testcase_11 AC 4 ms
9,572 KB
testcase_12 AC 4 ms
9,664 KB
testcase_13 AC 6 ms
9,600 KB
testcase_14 AC 6 ms
9,528 KB
testcase_15 AC 6 ms
9,604 KB
testcase_16 AC 6 ms
9,848 KB
testcase_17 AC 6 ms
9,564 KB
testcase_18 AC 467 ms
17,512 KB
testcase_19 AC 469 ms
17,552 KB
testcase_20 AC 471 ms
17,596 KB
testcase_21 AC 471 ms
17,536 KB
testcase_22 AC 471 ms
17,520 KB
testcase_23 AC 395 ms
19,772 KB
testcase_24 AC 395 ms
19,716 KB
testcase_25 AC 385 ms
19,780 KB
testcase_26 AC 421 ms
19,856 KB
testcase_27 AC 412 ms
19,856 KB
testcase_28 AC 520 ms
38,848 KB
testcase_29 AC 514 ms
40,556 KB
testcase_30 AC 506 ms
38,524 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:24:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   24 | main()
      | ^~~~

ソースコード

diff #

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