結果
問題 |
No.763 Noelちゃんと木遊び
|
ユーザー |
|
提出日時 | 2021-12-23 15:35:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 763 bytes |
コンパイル時間 | 922 ms |
コンパイル使用メモリ | 82,100 KB |
実行使用メモリ | 814,852 KB |
最終ジャッジ日時 | 2024-09-17 14:01:25 |
合計ジャッジ時間 | 5,972 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | MLE * 1 -- * 20 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<bool> visited; vector<bool> used; void dfs(vector<vector<int> > graph, int i){ visited[i] = true; bool used_flg = true; for (int j : graph[i]){ if (visited[j]) continue; dfs(graph, j) ; if (used[j]) used_flg=false; } used[i] = used_flg; } int main() { int N; cin >> N; vector<vector<int> > graph(N); for (int i = 1; i < N; i++) { int a, b; cin >> a >> b; graph[a - 1].push_back(b - 1); graph[b - 1].push_back(a - 1); } used.assign(N, false); visited.assign(N, false); dfs(graph,0); int ans = 0; for (auto i:used){ if (i) ans++; } cout << ans << endl; return 0; }