結果

問題 No.1719 Tree and Permutation
ユーザー square1001square1001
提出日時 2021-10-22 23:00:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 433 ms / 2,000 ms
コード長 511 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 79,328 KB
実行使用メモリ 9,260 KB
最終ジャッジ日時 2023-10-24 14:32:31
合計ジャッジ時間 3,551 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 284 ms
4,348 KB
testcase_02 AC 249 ms
4,348 KB
testcase_03 AC 433 ms
9,260 KB
testcase_04 AC 367 ms
8,288 KB
testcase_05 AC 385 ms
8,956 KB
testcase_06 AC 383 ms
8,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int Q;
	cin >> Q;
	while (Q--) {
		int N;
		cin >> N;
		vector<vector<int> > G(N);
		for (int i = 0; i < N - 1; ++i) {
			int a, b;
			cin >> a >> b; --a, --b;
			G[a].push_back(b);
			G[b].push_back(a);
		}
		int degree1 = 0;
		for (int i = 0; i < N; ++i) {
			if (G[i].size() == 1) {
				++degree1;
			}
		}
		cout << (degree1 * 2 >= N ? "Yes" : "No") << endl;
	}
	return 0;
}
0