結果

問題 No.1424 Ultrapalindrome
ユーザー Example0911Example0911
提出日時 2021-03-12 21:48:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 815 bytes
コンパイル時間 2,538 ms
コンパイル使用メモリ 204,036 KB
実行使用メモリ 13,984 KB
最終ジャッジ日時 2024-04-22 12:39:59
合計ジャッジ時間 6,712 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
13,764 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 39 ms
9,416 KB
testcase_10 AC 42 ms
9,472 KB
testcase_11 AC 30 ms
8,768 KB
testcase_12 AC 40 ms
9,216 KB
testcase_13 AC 12 ms
6,976 KB
testcase_14 AC 29 ms
8,768 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 25 ms
7,936 KB
testcase_17 AC 29 ms
8,704 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

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);
	}
	for (int i = 0; i < N; i++) {
		if (G[i].size() == 1) {
			dfs(i, -1, 0);
			set<int>st;
			for (int i = 0; i < N; i++) {
				if (G[i].size() == 1) {
					st.insert(depth[i]);
				}
			}
			if (st.size() > 2) {
				cout << "No" << endl; return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}
0