結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー |
![]() |
提出日時 | 2024-05-06 22:00:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 93 ms / 2,000 ms |
コード長 | 507 bytes |
コンパイル時間 | 726 ms |
コンパイル使用メモリ | 71,936 KB |
実行使用メモリ | 17,536 KB |
最終ジャッジ日時 | 2024-11-29 08:22:19 |
合計ジャッジ時間 | 3,735 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
using namespace std;#include<iostream>#include<vector>#include<algorithm>int dp[100009][2];vector<int> E[100009];void dfs(int cu, int pa = -1) {dp[cu][1] = 1;for (auto to : E[cu]) if(to!=pa){dfs(to, cu);dp[cu][0] += max(dp[to][0], dp[to][1]);dp[cu][1] += max(dp[to][0], dp[to][1] - 1);}}int main() {int N;cin >> N;for (int i = 0; i < N - 1; i++) {int x, y;cin >> x >> y;x--, y--;E[x].push_back(y);E[y].push_back(x);}dfs(0);cout << max(dp[0][0], dp[0][1]);}