結果
問題 | No.1719 Tree and Permutation |
ユーザー | Kude |
提出日時 | 2021-10-22 23:38:24 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 184 ms / 2,000 ms |
コード長 | 1,056 bytes |
コンパイル時間 | 3,984 ms |
コンパイル使用メモリ | 262,940 KB |
実行使用メモリ | 9,260 KB |
最終ジャッジ日時 | 2023-10-24 15:50:36 |
合計ジャッジ時間 | 5,870 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 90 ms
4,348 KB |
testcase_02 | AC | 122 ms
4,348 KB |
testcase_03 | AC | 184 ms
9,260 KB |
testcase_04 | AC | 166 ms
8,284 KB |
testcase_05 | AC | 173 ms
8,956 KB |
testcase_06 | AC | 170 ms
8,940 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template<class T> void chmax(T& a, const T& b) {a = max(a, b);} template<class T> void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while(tt--) { int n; cin >> n; VVI to(n); rep(i, n - 1) { int a, b; cin >> a >> b; a--, b--; to[a].push_back(b); to[b].push_back(a); } int leaf = 0; rep(i, n) leaf += to[i].size() == 1; int non_leaf = n - leaf; bool ok = leaf >= non_leaf; cout << (ok ? "Yes\n" : "No\n"); } }