結果

問題 No.763 Noelちゃんと木遊び
ユーザー kotatsugamekotatsugame
提出日時 2018-12-13 01:08:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 454 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 72,276 KB
実行使用メモリ 18,416 KB
最終ジャッジ日時 2023-10-25 08:49:18
合計ジャッジ時間 3,010 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
18,416 KB
testcase_01 AC 31 ms
8,044 KB
testcase_02 AC 73 ms
9,812 KB
testcase_03 AC 47 ms
8,824 KB
testcase_04 AC 35 ms
8,232 KB
testcase_05 AC 46 ms
8,764 KB
testcase_06 AC 90 ms
10,468 KB
testcase_07 AC 86 ms
10,332 KB
testcase_08 AC 51 ms
8,928 KB
testcase_09 AC 34 ms
8,184 KB
testcase_10 AC 14 ms
7,300 KB
testcase_11 AC 92 ms
10,544 KB
testcase_12 AC 82 ms
10,116 KB
testcase_13 AC 80 ms
10,052 KB
testcase_14 AC 71 ms
9,692 KB
testcase_15 AC 51 ms
8,800 KB
testcase_16 AC 10 ms
7,080 KB
testcase_17 AC 51 ms
8,812 KB
testcase_18 AC 94 ms
10,492 KB
testcase_19 AC 83 ms
10,144 KB
testcase_20 AC 84 ms
10,164 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,d[1<<17],p[1<<17];
vector<int>G[1<<17];
void dfs(int u,int P)
{
	d[u]=1;
	for(int i=0;i<G[u].size();i++)
	{
		if(G[u][i]==P)continue;
		dfs(G[u][i],u);
		d[u]+=p[G[u][i]];
		p[u]+=max(p[G[u][i]],d[G[u][i]]);
	}
}
main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int a,b;cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(1,0);
	cout<<(d[1]<p[1]?p[1]:d[1])<<endl;
}
0