結果

問題 No.763 Noelちゃんと木遊び
ユーザー ttkkggwwttkkggww
提出日時 2020-03-31 22:18:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 610 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 168,316 KB
実行使用メモリ 16,348 KB
最終ジャッジ日時 2023-09-07 12:58:43
合計ジャッジ時間 4,389 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
16,348 KB
testcase_01 AC 27 ms
5,404 KB
testcase_02 AC 70 ms
8,632 KB
testcase_03 AC 44 ms
6,840 KB
testcase_04 AC 33 ms
5,632 KB
testcase_05 AC 43 ms
6,660 KB
testcase_06 AC 89 ms
9,896 KB
testcase_07 AC 82 ms
9,424 KB
testcase_08 AC 48 ms
7,068 KB
testcase_09 AC 30 ms
5,632 KB
testcase_10 AC 12 ms
4,380 KB
testcase_11 AC 90 ms
9,936 KB
testcase_12 AC 75 ms
9,340 KB
testcase_13 AC 75 ms
9,180 KB
testcase_14 AC 66 ms
8,276 KB
testcase_15 AC 42 ms
6,844 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 43 ms
6,664 KB
testcase_18 AC 88 ms
9,936 KB
testcase_19 AC 80 ms
9,336 KB
testcase_20 AC 76 ms
9,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int n;
vector<vector<int>> M;
ll dp[101010][2];
//dp[i][j]j..切るか切らないかの時の数

void dfs(int now,int p = -1)
{
	for(auto i:M[now])
	{
		if(p!=i)
		{
			dfs(i,now);
			dp[now][0] += max(dp[i][0]-1,dp[i][1]);
			dp[now][1] += max(dp[i][0],dp[i][1]);
		}
	}	
}
int main()
{
	cin >> n;	
	M = vector<vector<int>>(n);
	for(int i = 0;i<n-1;++i)
	{
		int x,y;
		cin >> x >> y;
		x--;y--;
		M[x].push_back(y);
		M[y].push_back(x);
	}
	for(int i = 0;i<n+1;i++){dp[i][0]++;}
	dfs(0);
	cout<<max(dp[0][1],dp[0][0])<<endl;
	return 0;
}
0