結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー |
|
提出日時 | 2021-10-17 15:04:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 695 bytes |
コンパイル時間 | 1,416 ms |
コンパイル使用メモリ | 173,640 KB |
実行使用メモリ | 16,512 KB |
最終ジャッジ日時 | 2024-09-17 19:41:03 |
合計ジャッジ時間 | 3,878 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>using namespace std;void rec(vector<vector<int>> &G, vector<bool> &used, int v, int p) {bool used_child = false;for (int w : G[v]) {if (w == p) continue;rec(G, used, w, v);if (used[w]) used_child = true;}if (!used_child) used[v] = true;}int main() {int N;cin >> N;vector<vector<int>> G(N);for (int i = 0; i < N-1; i++) {int u, v;cin >> u >> v;u--;v--;G[u].push_back(v);G[v].push_back(u);}vector<bool> used(N, false);rec(G, used, 0, -1);int ans = 0;for (int i = 0; i < N; i++) ans += used[i];cout << ans << endl;}