結果
問題 |
No.763 Noelちゃんと木遊び
|
ユーザー |
![]() |
提出日時 | 2019-08-16 05:06:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 673 bytes |
コンパイル時間 | 1,461 ms |
コンパイル使用メモリ | 165,136 KB |
実行使用メモリ | 15,616 KB |
最終ジャッジ日時 | 2025-03-22 10:36:41 |
合計ジャッジ時間 | 3,968 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, m, n) for (int i = m; i < n; ++i) int N; vector<vector<int>> G; int dp[101010][2]; void dfs(int cur, int pre = -1) { dp[cur][0] = 1; dp[cur][1] = 0; for(auto &to : G[cur]) { if(to == pre) continue; dfs(to, cur); dp[cur][0] += max(dp[to][0] - 1, dp[to][1]); dp[cur][1] += max(dp[to][0], dp[to][1]); } } int main() { cin >> N; G.resize(N); rep(i, 0, N - 1) { int x, y; cin >> x >> y; x--, y--; G[x].push_back(y); G[y].push_back(x); } dfs(0); cout << max(dp[0][0], dp[0][1]) << endl; return 0; }