結果
問題 |
No.806 木を道に
|
ユーザー |
|
提出日時 | 2019-03-22 21:36:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 708 bytes |
コンパイル時間 | 1,752 ms |
コンパイル使用メモリ | 196,092 KB |
最終ジャッジ日時 | 2025-01-06 23:46:17 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 4 WA * 23 |
コンパイルメッセージ
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 = 100000; vector<int> edges[MAX]; bool used[MAX]; int path = 0; 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){ path += 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]) path++; if(path <= 3){ cout << path-1 << endl; }else{ cout << 2*path-4 << endl; } return 0; }