結果

問題 No.1424 Ultrapalindrome
ユーザー 👑 NachiaNachia
提出日時 2021-03-12 22:30:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 951 bytes
コンパイル時間 4,867 ms
コンパイル使用メモリ 257,944 KB
実行使用メモリ 9,972 KB
最終ジャッジ日時 2024-04-22 13:33:33
合計ジャッジ時間 6,603 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 WA -
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,816 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 WA -
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 WA -
testcase_09 AC 41 ms
8,064 KB
testcase_10 AC 42 ms
8,064 KB
testcase_11 AC 28 ms
6,940 KB
testcase_12 AC 39 ms
7,808 KB
testcase_13 AC 10 ms
6,944 KB
testcase_14 AC 31 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 24 ms
6,940 KB
testcase_17 AC 29 ms
6,940 KB
testcase_18 AC 18 ms
6,940 KB
testcase_19 AC 27 ms
6,944 KB
testcase_20 AC 7 ms
6,940 KB
testcase_21 AC 22 ms
6,944 KB
testcase_22 AC 14 ms
6,944 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 6 ms
6,940 KB
testcase_25 AC 6 ms
6,940 KB
testcase_26 AC 35 ms
7,424 KB
testcase_27 WA -
testcase_28 AC 33 ms
9,344 KB
testcase_29 WA -
testcase_30 AC 29 ms
9,968 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0