結果
問題 |
No.1424 Ultrapalindrome
|
ユーザー |
![]() |
提出日時 | 2021-03-12 21:46:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 727 bytes |
コンパイル時間 | 1,926 ms |
コンパイル使用メモリ | 200,512 KB |
最終ジャッジ日時 | 2025-01-19 14:29:54 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 WA * 6 |
ソースコード
#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); } dfs(0, -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 << "Yes" << endl; } else cout << "No" << endl; return 0; }