結果
問題 | No.1424 Ultrapalindrome |
ユーザー |
👑 ![]() |
提出日時 | 2021-03-12 22:30:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 951 bytes |
コンパイル時間 | 3,761 ms |
コンパイル使用メモリ | 255,388 KB |
最終ジャッジ日時 | 2025-01-19 15:13:37 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 24 WA * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:14:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%d",&N); | ~~~~~^~~~~~~~~ main.cpp:17:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | int u,v; scanf("%d%d",&u,&v); u--; v--; | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <atcoder/all> #include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) using mll=atcoder::static_modint<1000000007>; int N; vector<vector<int>> E; vector<int> D; int main(){ scanf("%d",&N); E.resize(N); rep(i,N-1){ int u,v; scanf("%d%d",&u,&v); u--; v--; E[u].push_back(v); E[v].push_back(u); } queue<int> Q; D.assign(N,-1); rep(i,N) if(E[i].size()==1){ D[i]=0; Q.push(i); } while(Q.size()){ int p=Q.front(); Q.pop(); for(int e:E[p]) if(D[e]==-1){ D[e]=D[p]+1; Q.push(e); } } int maxD=0; rep(i,N) maxD=max(maxD,D[i]); bool ok=true; int centEdge=0; rep(p,N){ int X[3]={}; for(int e:E[p]){ int dD=abs(D[e]-D[p]); if(dD==1) continue; if(dD==0){ centEdge++; continue; } printf("No\n"); return 0; } } if(centEdge>2){ printf("No\n"); return 0; } printf("Yes\n"); return 0; }