結果

問題 No.806 木を道に
ユーザー ei1333333
提出日時 2019-03-22 21:23:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 578 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 194,760 KB
最終ジャッジ日時 2025-01-06 23:41:08
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 7 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i=0;i<n;i++)

vector< int > G[200000];
int ans;
bool used[200000];

int dfs(int id) {
  int ret = 0;
  used[id] = true;
  rep(j, G[id].size()) {
    int to = G[id][j];
    if(used[to])continue;
    if(dfs(to) >= 2)ans++;
    else ret++;
  }
  ans += max(ret - 2, 0);
  ret = min(ret, 2);
  return ret;
}

int main() {
  int n;
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(0);
  cout << ans << endl;
  return 0;
}
0