結果
| 問題 | No.763 Noelちゃんと木遊び | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-12-13 01:08:34 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 107 ms / 2,000 ms | 
| コード長 | 454 bytes | 
| コンパイル時間 | 735 ms | 
| コンパイル使用メモリ | 69,520 KB | 
| 実行使用メモリ | 18,304 KB | 
| 最終ジャッジ日時 | 2025-03-22 10:34:39 | 
| 合計ジャッジ時間 | 3,301 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 22 | 
コンパイルメッセージ
main.cpp:18:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
   18 | main()
      | ^~~~
            
            ソースコード
#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;
}
            
            
            
        