結果

問題 No.1424 Ultrapalindrome
ユーザー 👑 NachiaNachia
提出日時 2021-03-12 22:54:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 892 bytes
コンパイル時間 4,540 ms
コンパイル使用メモリ 257,384 KB
実行使用メモリ 10,104 KB
最終ジャッジ日時 2024-04-22 14:21:59
合計ジャッジ時間 6,185 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
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 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 33 ms
7,808 KB
testcase_10 AC 36 ms
7,552 KB
testcase_11 AC 24 ms
6,272 KB
testcase_12 AC 31 ms
7,296 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 26 ms
6,528 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 22 ms
6,016 KB
testcase_17 AC 26 ms
6,528 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 4 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 45 ms
8,960 KB
testcase_28 AC 33 ms
8,704 KB
testcase_29 AC 34 ms
9,216 KB
testcase_30 AC 29 ms
9,976 KB
testcase_31 AC 32 ms
10,104 KB
権限があれば一括ダウンロードができます

ソースコード

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; Q.push(splitCount);
  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