結果
| 問題 |
No.763 Noelちゃんと木遊び
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-18 16:18:18 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 2,000 ms |
| コード長 | 763 bytes |
| コンパイル時間 | 5,575 ms |
| コンパイル使用メモリ | 282,748 KB |
| 実行使用メモリ | 16,512 KB |
| 最終ジャッジ日時 | 2025-03-22 10:44:10 |
| 合計ジャッジ時間 | 5,486 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
vector<bool> used;
void dfs(const Graph &a, int v, int p) {
bool exit = false;
for (auto ch : a[v]) {
if (ch == p) continue;
dfs(a, ch, v);
if (used[ch]) exit = true;
}
if (!exit) used[v] = true;
}
void solved() {
int n;
cin >> n;
Graph a(n + 1);
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
a[u].emplace_back(v);
a[v].emplace_back(u);
}
used.assign(n + 1, false);
dfs(a, 1, -1);
int ans = 0;
for (int i = 1; i <= n; i++) {
if (used[i]) ans++;
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
/*int t = 1;
cin >> t;
while (t--)*/
solved();
return 0;
}