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