結果

問題 No.1719 Tree and Permutation
ユーザー SSRSSSRS
提出日時 2021-10-22 23:05:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 576 bytes
コンパイル時間 1,752 ms
コンパイル使用メモリ 170,096 KB
実行使用メモリ 4,652 KB
最終ジャッジ日時 2023-10-24 14:40:47
合計ジャッジ時間 3,959 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 257 ms
4,348 KB
testcase_02 AC 189 ms
4,348 KB
testcase_03 AC 278 ms
4,492 KB
testcase_04 AC 272 ms
4,492 KB
testcase_05 AC 274 ms
4,652 KB
testcase_06 AC 274 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    int N;
    cin >> N;
    vector<int> A(N - 1), B(N - 1);
    for (int j = 0; j < N - 1; j++){
      cin >> A[j] >> B[j];
      A[j]--;
      B[j]--;
    }
    vector<int> d(N, 0);
    for (int j = 0; j < N - 1; j++){
      d[A[j]]++;
      d[B[j]]++;
    }
    int cnt = 0;
    for (int j = 0; j < N; j++){
      if (d[j] == 1){
        cnt++;
      }
    }
    if (cnt * 2 >= N){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
0