結果
| 問題 |
No.763 Noelちゃんと木遊び
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-12 19:21:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 54 ms / 2,000 ms |
| コード長 | 665 bytes |
| コンパイル時間 | 1,608 ms |
| コンパイル使用メモリ | 166,636 KB |
| 実行使用メモリ | 14,868 KB |
| 最終ジャッジ日時 | 2025-03-22 10:34:42 |
| 合計ジャッジ時間 | 3,361 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector< vector<int> > G;
int dfs(int cur, int par, int& cnt) {
int res = 0;
for (int nex : G[cur]) {
if (nex == par) continue;
if (dfs(nex, cur, cnt) == 0) {
res = 1;
}
}
cnt += (res == 0);
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
G.resize(n);
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
u--; v--;
G[u].push_back(v);
G[v].push_back(u);
}
int ans = 0;
dfs(0, -1, ans);
cout << ans << endl;
return 0;
}