結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー |
![]() |
提出日時 | 2019-02-18 23:26:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 931 bytes |
コンパイル時間 | 1,029 ms |
コンパイル使用メモリ | 95,476 KB |
実行使用メモリ | 13,568 KB |
最終ジャッジ日時 | 2024-10-08 15:36:15 |
合計ジャッジ時間 | 2,929 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <string>#include <vector>#include <queue>#include <cmath>#include <stack>#include <set>#include <map>typedef long long ll;typedef unsigned int uint;using namespace std;typedef pair<int, int> P;int n;bool visited[100005];vector <int> edge[100005];P dfs(int x) {visited[x] = true;P ret = P(1, 0);for (int i: edge[x]) {if (visited[i]) continue;P p = dfs(i);ret.first += max(p.first - 1, p.second);ret.second += max(p.first, p.second);}return ret;}int main() {cin.sync_with_stdio(false);cin.tie(0);cin >> n;for (int i = 0; i < n-1; i++) {int u, v;cin >> u >> v;u--; v--;edge[u].push_back(v);edge[v].push_back(u);}P p = dfs(0);cout << max(p.first, p.second) << "\n";return 0;}