結果

問題 No.1719 Tree and Permutation
ユーザー SSRS
提出日時 2021-10-22 23:05:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 279 ms / 2,000 ms
コード長 576 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 169,804 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-23 07:00:18
合計ジャッジ時間 4,019 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

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