結果
問題 |
No.1424 Ultrapalindrome
|
ユーザー |
|
提出日時 | 2021-03-12 21:30:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 786 bytes |
コンパイル時間 | 1,679 ms |
コンパイル使用メモリ | 171,100 KB |
実行使用メモリ | 16,896 KB |
最終ジャッジ日時 | 2024-10-14 11:38:32 |
合計ジャッジ時間 | 3,406 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 27 WA * 2 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Graph=vector<vector<int>>; void rep(int v,int pv,int d,vector<int> &res,Graph &g){ res[v]=d; for(auto &nx : g[v]){ if(nx==pv){continue;} rep(nx,v,d+1,res,g); } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; Graph g(n); for(int i=1;i<n;i++){ int u,v; cin >> u >> v; u--;v--; g[u].push_back(v); g[v].push_back(u); } vector<int> d(n); rep(0,-1,0,d,g); int fv=0; for(int i=0;i<n;i++){if(d[fv]<d[i]){fv=i;}} rep(fv,-1,0,d,g); int sv=0; for(int i=0;i<n;i++){if(d[sv]<d[i]){sv=i;}} for(int i=0;i<n;i++){ if(i==fv){continue;} if(g[i].size()==1){ if(d[sv]!=d[i]){cout << "No\n";return 0;} } } cout << "Yes\n"; return 0; }