結果
問題 |
No.1424 Ultrapalindrome
|
ユーザー |
![]() |
提出日時 | 2021-03-12 22:00:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 816 bytes |
コンパイル時間 | 1,832 ms |
コンパイル使用メモリ | 201,376 KB |
最終ジャッジ日時 | 2025-01-19 14:43:54 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 16 WA * 4 TLE * 9 |
ソースコード
#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 << "Yes" << endl; return 0; } } } cout << "No" << endl; return 0; }