結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー |
|
提出日時 | 2024-10-18 16:18:18 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 763 bytes |
コンパイル時間 | 4,011 ms |
コンパイル使用メモリ | 255,868 KB |
実行使用メモリ | 16,512 KB |
最終ジャッジ日時 | 2024-10-18 16:18:25 |
合計ジャッジ時間 | 6,707 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#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;}