結果
| 問題 | No.806 木を道に |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-03-22 21:36:17 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 708 bytes |
| 記録 | |
| コンパイル時間 | 1,177 ms |
| コンパイル使用メモリ | 212,132 KB |
| 実行使用メモリ | 14,976 KB |
| 最終ジャッジ日時 | 2026-06-07 08:40:53 |
| 合計ジャッジ時間 | 2,597 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 WA * 23 |
ソースコード
#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;
}