結果
| 問題 | 
                            No.1424 Ultrapalindrome
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Example0911
                         | 
                    
| 提出日時 | 2021-03-12 21:51:25 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 867 bytes | 
| コンパイル時間 | 1,985 ms | 
| コンパイル使用メモリ | 199,716 KB | 
| 最終ジャッジ日時 | 2025-01-19 14:34:13 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 WA * 4 | 
ソースコード
#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 j = 0; j < N; j++) {
				if (G[j].size() == 1) {
					st.insert(depth[j]);
				}
			}
			if (st.size() > 2) {
				cout << "No" << endl; return 0;
			}
			else {
				cout << "Yes" << endl; return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}
            
            
            
        
            
Example0911