結果

問題 No.1928 Make a Binary Tree
ユーザー SSRSSSRS
提出日時 2022-05-06 22:27:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 809 bytes
コンパイル時間 1,834 ms
コンパイル使用メモリ 175,184 KB
実行使用メモリ 27,444 KB
最終ジャッジ日時 2023-09-20 03:26:22
合計ジャッジ時間 11,104 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,384 KB
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 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 147 ms
25,344 KB
testcase_37 WA -
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 194 ms
25,752 KB
testcase_40 AC 194 ms
25,812 KB
testcase_41 AC 194 ms
25,768 KB
testcase_42 AC 191 ms
25,916 KB
testcase_43 AC 195 ms
25,952 KB
testcase_44 AC 191 ms
25,952 KB
testcase_45 AC 194 ms
25,808 KB
testcase_46 AC 193 ms
25,732 KB
testcase_47 AC 192 ms
25,752 KB
testcase_48 AC 192 ms
25,876 KB
testcase_49 AC 156 ms
27,312 KB
testcase_50 AC 259 ms
24,476 KB
testcase_51 AC 256 ms
24,528 KB
testcase_52 AC 254 ms
24,644 KB
testcase_53 AC 255 ms
24,532 KB
testcase_54 AC 253 ms
24,740 KB
testcase_55 AC 151 ms
24,336 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 143 ms
23,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<int>> E(N);
  for (int i = 0; i < N - 1; i++){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    E[x].push_back(y);
    E[y].push_back(x);
  }
  vector<int> p(N, -1);
  vector<vector<int>> c(N);
  vector<int> bfs;
  queue<int> Q;
  Q.push(0);
  while (!Q.empty()){
    int v = Q.front();
    Q.pop();
    bfs.push_back(v);
    for (int w : E[v]){
      if (w != p[v]){
        p[w] = v;
        c[v].push_back(w);
        Q.push(w);
      }
    }
  }
  reverse(bfs.begin(), bfs.end());
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    A[i] = c[i].size();
  }
  for (int v : bfs){
    if (A[v] >= 3 && v > 0){
      A[p[v]] += A[v] - 2;
      A[v] = 2;
    }
  }
  cout << N - max(A[0] - 2, 0) << endl;
}
0