結果

問題 No.1424 Ultrapalindrome
ユーザー 👑 NachiaNachia
提出日時 2021-03-12 22:55:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 923 bytes
コンパイル時間 4,616 ms
コンパイル使用メモリ 259,156 KB
実行使用メモリ 9,204 KB
最終ジャッジ日時 2024-04-22 14:22:39
合計ジャッジ時間 8,707 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 38 ms
7,808 KB
testcase_10 AC 37 ms
7,680 KB
testcase_11 AC 25 ms
6,400 KB
testcase_12 AC 35 ms
7,296 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 28 ms
6,784 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 20 ms
5,888 KB
testcase_17 AC 26 ms
6,400 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 46 ms
8,832 KB
testcase_28 AC 33 ms
8,704 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

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);
  }
  int splitCount=0;
  rep(i,N) if(E[i].size()>2) splitCount++;
  if(splitCount==0){ printf("Yes\n"); return 0; }
  if(splitCount>=2){ printf("No\n"); return 0; }

  queue<int> Q;
  rep(i,N) if(E[i].size()>2){ D[i]=0; Q.push(i); }
  D.assign(N,-1);
  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 x=-1;
  rep(i,N) if(E[i].size()==1){
    if(x==-1) x=D[i];
    else if(x!=D[i]){ printf("No\n"); return 0; }
  }
  
  printf("Yes\n");
  return 0;
}
0