結果
| 問題 |
No.763 Noelちゃんと木遊び
|
| コンテスト | |
| ユーザー |
veqcc
|
| 提出日時 | 2019-02-18 23:26:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 60 ms / 2,000 ms |
| コード長 | 931 bytes |
| コンパイル時間 | 836 ms |
| コンパイル使用メモリ | 93,704 KB |
| 実行使用メモリ | 13,824 KB |
| 最終ジャッジ日時 | 2025-03-22 10:35:30 |
| 合計ジャッジ時間 | 2,690 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#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;
}
veqcc