結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー |
![]() |
提出日時 | 2018-12-11 18:28:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,610 ms / 2,000 ms |
コード長 | 735 bytes |
コンパイル時間 | 582 ms |
コンパイル使用メモリ | 71,864 KB |
実行使用メモリ | 20,736 KB |
最終ジャッジ日時 | 2024-09-22 06:26:43 |
合計ジャッジ時間 | 25,641 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <vector>#include <cstdio>#include <iostream>using namespace std;vector<int> adj[100100];int memo[2][100100];int calc(int i, int use, int p = -1) {if (memo[use][i] >= 0) return memo[use][i];int sum = use;for (int j : adj[i])if (j != p)sum += use ? calc(j, 0, i) : max(calc(j, 0, i), calc(j, 1, i));cerr << use << ' ' << i << ' ' << sum << endl;return memo[use][i] = sum;}int main() {int n; cin >> n;for (int i = 1; i < n; i++) {int x, y; scanf(" %d %d", &x, &y);adj[x].push_back(y); adj[y].push_back(x);}fill(memo[0], memo[0] + n + 1, -1);fill(memo[1], memo[1] + n + 1, -1);cout << max(calc(1, 1), calc(1, 0)) << endl;}