結果

問題 No.1424 Ultrapalindrome
ユーザー Example0911Example0911
提出日時 2021-03-12 22:20:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 902 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 202,276 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-04-22 17:11:15
合計ジャッジ時間 6,217 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,016 KB
testcase_01 AC 2 ms
5,888 KB
testcase_02 AC 3 ms
6,016 KB
testcase_03 AC 3 ms
5,888 KB
testcase_04 AC 3 ms
5,888 KB
testcase_05 AC 3 ms
5,888 KB
testcase_06 AC 2 ms
5,888 KB
testcase_07 AC 2 ms
5,888 KB
testcase_08 AC 3 ms
5,888 KB
testcase_09 AC 33 ms
9,432 KB
testcase_10 AC 34 ms
9,440 KB
testcase_11 AC 25 ms
8,376 KB
testcase_12 AC 32 ms
9,132 KB
testcase_13 AC 10 ms
6,784 KB
testcase_14 AC 26 ms
8,732 KB
testcase_15 AC 3 ms
5,888 KB
testcase_16 AC 20 ms
8,168 KB
testcase_17 AC 25 ms
8,644 KB
testcase_18 AC 171 ms
7,296 KB
testcase_19 AC 621 ms
8,172 KB
testcase_20 AC 93 ms
6,272 KB
testcase_21 AC 94 ms
7,808 KB
testcase_22 AC 303 ms
6,944 KB
testcase_23 AC 14 ms
6,272 KB
testcase_24 AC 15 ms
6,400 KB
testcase_25 AC 24 ms
6,272 KB
testcase_26 AC 791 ms
8,576 KB
testcase_27 WA -
testcase_28 AC 33 ms
12,672 KB
testcase_29 AC 32 ms
12,800 KB
testcase_30 AC 145 ms
11,216 KB
testcase_31 AC 29 ms
11,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define int long long
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 1000000007;

int N;
vector<int>G[100010];
int depth[100010];
void dfs(int v, int p, int d) {
	depth[v] = d;
	for (auto nv : G[v]) {
		if (nv == p)continue;
		dfs(nv, v, d + 1);
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> 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);
	}
	vector<int>v;
	for (int i = 0; i < N; i++) {
		if (G[i].size() == 1)v.push_back(i);
	}
	for (int i = 0; i < min((int)v.size(), 200LL); i++) {
		dfs(v[i], -1, 0);
			set<int>st;
			for (int j = 0; j < N; j++) {
				if (G[j].size() == 1) {
					st.insert(depth[j]);
				}
			}
			if (st.size() > 2) {
				cout << "No" << endl; return 0;
			}
		
	}
	cout << "Yes" << endl;
	return 0;
}
0