結果

問題 No.1424 Ultrapalindrome
ユーザー nikkukunnikkukun
提出日時 2021-03-14 22:07:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,323 bytes
コンパイル時間 2,247 ms
コンパイル使用メモリ 181,484 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-04-24 03:41:04
合計ジャッジ時間 3,418 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 4 ms
8,576 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 4 ms
8,576 KB
testcase_05 AC 4 ms
8,576 KB
testcase_06 WA -
testcase_07 AC 4 ms
8,576 KB
testcase_08 AC 4 ms
8,576 KB
testcase_09 AC 4 ms
8,704 KB
testcase_10 AC 4 ms
8,704 KB
testcase_11 AC 4 ms
8,680 KB
testcase_12 AC 4 ms
8,688 KB
testcase_13 AC 4 ms
8,576 KB
testcase_14 AC 4 ms
8,576 KB
testcase_15 AC 4 ms
8,704 KB
testcase_16 AC 4 ms
8,704 KB
testcase_17 AC 4 ms
8,832 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 4 ms
8,596 KB
testcase_28 WA -
testcase_29 AC 5 ms
8,704 KB
testcase_30 WA -
testcase_31 AC 4 ms
8,704 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);

	freopen("C.in", "r", stdin);

	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