結果
問題 |
No.806 木を道に
|
ユーザー |
|
提出日時 | 2019-03-22 21:32:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 632 bytes |
コンパイル時間 | 1,737 ms |
コンパイル使用メモリ | 196,216 KB |
最終ジャッジ日時 | 2025-01-06 23:44:54 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 7 WA * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:28:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | scanf("%d %d", &a, &b); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; int N; const int MAX = 200000; vector<int> edges[MAX]; bool used[MAX]; int ans = -1; void dfs(int i, int p){ int c = 0; for(auto j : edges[i]){ if(j == p) continue; dfs(j, i); if(used[j]) continue; c++; } if(c >= 2){ ans += c-1; used[i] = true; } } int main(){ cin >> N; for(int i=0; i<N-1; i++){ int a, b; scanf("%d %d", &a, &b); edges[a-1].push_back(b-1); edges[b-1].push_back(a-1); } dfs(0, -1); if(!used[0]) ans += 1; cout << ans << endl; return 0; }