結果

問題 No.806 木を道に
ユーザー pekempeypekempey
提出日時 2019-03-22 21:28:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 544 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 72,008 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2023-10-19 06:27:54
合計ジャッジ時間 2,751 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,080 KB
testcase_01 AC 3 ms
6,080 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 3 ms
6,080 KB
testcase_08 AC 3 ms
6,080 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 41 ms
11,224 KB
testcase_25 AC 61 ms
13,888 KB
testcase_26 AC 21 ms
7,020 KB
testcase_27 AC 65 ms
9,236 KB
testcase_28 AC 5 ms
6,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

vector<int> G[100000];
int ans;
int cnt[100000];

void dfs(int u, int p) {
  for (int v : G[u]) if (v != p) {
    dfs(v, u);
    if (cnt[u] < 2 && cnt[v] < 2) {
      cnt[u]++;
      cnt[v]++;
      ans--;
    }
  }
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  ans = N - 1;
  dfs(0, -1);
  cout << ans << '\n';
}
0