結果

問題 No.1424 Ultrapalindrome
ユーザー msm1993msm1993
提出日時 2021-03-23 15:28:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,292 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 181,348 KB
実行使用メモリ 14,456 KB
最終ジャッジ日時 2023-08-16 17:38:36
合計ジャッジ時間 5,985 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,516 KB
testcase_01 AC 4 ms
9,564 KB
testcase_02 AC 4 ms
9,560 KB
testcase_03 AC 4 ms
9,672 KB
testcase_04 AC 4 ms
9,536 KB
testcase_05 AC 5 ms
9,492 KB
testcase_06 AC 5 ms
9,564 KB
testcase_07 AC 4 ms
9,552 KB
testcase_08 AC 5 ms
9,516 KB
testcase_09 AC 36 ms
12,816 KB
testcase_10 AC 36 ms
12,700 KB
testcase_11 AC 26 ms
11,868 KB
testcase_12 AC 36 ms
12,524 KB
testcase_13 AC 12 ms
10,616 KB
testcase_14 AC 29 ms
12,000 KB
testcase_15 AC 5 ms
9,564 KB
testcase_16 AC 24 ms
11,488 KB
testcase_17 AC 28 ms
11,992 KB
testcase_18 AC 19 ms
10,960 KB
testcase_19 AC 27 ms
11,388 KB
testcase_20 AC 10 ms
10,032 KB
testcase_21 AC 23 ms
10,952 KB
testcase_22 AC 16 ms
10,460 KB
testcase_23 AC 7 ms
9,828 KB
testcase_24 AC 9 ms
9,908 KB
testcase_25 AC 9 ms
9,896 KB
testcase_26 AC 33 ms
11,720 KB
testcase_27 AC 47 ms
13,448 KB
testcase_28 AC 33 ms
12,644 KB
testcase_29 AC 42 ms
12,620 KB
testcase_30 AC 31 ms
14,456 KB
testcase_31 AC 31 ms
14,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int vst[N];
vector<int> a[N];

int main() {
	ios::sync_with_stdio(0);

	queue<pint> q;
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		a[u].push_back(v);
		a[v].push_back(u);
	}

	for (int i = 1; i <= n; i++) {
		if (a[i].size() == 1) {
			q.push(make_pair(i, 0));
			vst[i] = 1;
		}
	}

	int siz = q.size();
	if (siz == 2) {
		cout << "Yes" << endl;
		return 0;
	}

	while (!q.empty()) {
		queue<pint> nq;
		while (!q.empty()) {
			pint p = q.front();
			q.pop();
			if (vst[p.fi] > 1) continue;
			for (auto v: a[p.fi]) {
				if (!vst[v] && v != p.se) {
					nq.push(make_pair(v, p.fi));
				}
			}
		}
		q = nq;
		while (!nq.empty()) {
			pint p = nq.front();
			nq.pop();
			vst[p.fi]++;
		}
	}

	static int cnt[N];
	for (int i = 1; i <= n; i++)
		cnt[vst[i]]++;
	bool flag = (cnt[1] == n - 1) && (cnt[siz] == 1);
	cout << (flag ? "Yes" : "No") << endl;

	return 0;
}
0