結果

問題 No.1719 Tree and Permutation
ユーザー square1001
提出日時 2021-10-22 23:00:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 511 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 80,452 KB
実行使用メモリ 9,200 KB
最終ジャッジ日時 2024-09-23 06:53:41
合計ジャッジ時間 3,625 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

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