結果
| 問題 |
No.763 Noelちゃんと木遊び
|
| コンテスト | |
| ユーザー |
utouto97
|
| 提出日時 | 2019-02-27 11:37:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 98 ms / 2,000 ms |
| コード長 | 1,316 bytes |
| コンパイル時間 | 1,348 ms |
| コンパイル使用メモリ | 157,996 KB |
| 実行使用メモリ | 18,244 KB |
| 最終ジャッジ日時 | 2025-03-22 10:35:41 |
| 合計ジャッジ時間 | 3,875 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;
/*{
dp[i][j]
iを根とする部分木で
j=0 iを削除しない
j=1 iを削除する
ときの連結成分の個数
}*/
vector<int> g[100000];
ll dp[100001][2];
void dfs(int x, int par = -1)
{
dp[x][0] = 1;
dp[x][1] = 0;
for(auto to : g[x]){
if(to == par) continue;
dfs(to, x);
dp[x][0] += dp[to][1];
dp[x][1] += max(dp[to][0], dp[to][1]);
}
// cout << x << " : " << dp[x][0] << " , " << dp[x][1] << endl;
}
int main()
{
int n;
cin >> n;
rep(i, n-1){
int x, y;
cin >> x >> y;
x--; y--;
g[x].pb(y);
g[y].pb(x);
}
dfs(0);
ll ans = max(dp[0][0], dp[0][1]);
cout << ans << endl;
return 0;
}
utouto97