結果

問題 No.763 Noelちゃんと木遊び
ユーザー chocoruskchocorusk
提出日時 2018-12-11 01:15:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 790 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 98,944 KB
実行使用メモリ 17,844 KB
最終ジャッジ日時 2023-10-24 22:25:12
合計ジャッジ時間 3,204 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
17,844 KB
testcase_01 AC 26 ms
7,624 KB
testcase_02 AC 59 ms
9,316 KB
testcase_03 AC 41 ms
8,400 KB
testcase_04 AC 30 ms
7,812 KB
testcase_05 AC 40 ms
8,336 KB
testcase_06 AC 72 ms
9,924 KB
testcase_07 AC 70 ms
9,792 KB
testcase_08 AC 44 ms
8,488 KB
testcase_09 AC 29 ms
7,764 KB
testcase_10 AC 12 ms
6,860 KB
testcase_11 AC 74 ms
9,988 KB
testcase_12 AC 65 ms
9,588 KB
testcase_13 AC 64 ms
9,536 KB
testcase_14 AC 57 ms
9,204 KB
testcase_15 AC 40 ms
8,368 KB
testcase_16 AC 8 ms
6,632 KB
testcase_17 AC 41 ms
8,380 KB
testcase_18 AC 73 ms
9,940 KB
testcase_19 AC 66 ms
9,624 KB
testcase_20 AC 66 ms
9,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> g[100000];
int dp[2][100000];
bool used[100000];
void dfs(int x){
	used[x]=1;
	dp[1][x]=1;
	for(auto y:g[x]){
		if(!used[y]){
			dfs(y);
			dp[1][x]+=dp[0][y];
			dp[0][x]+=max(dp[0][y], dp[1][y]);
		}
	}
}
int main()
{
	int n;
	cin>>n;
	for(int i=0; i<n-1; i++){
		int u, v;
		cin>>u>>v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0);
	cout<<max(dp[0][0], dp[1][0])<<endl;
	return 0;
}
0