結果

問題 No.1424 Ultrapalindrome
ユーザー fumofumofunifumofumofuni
提出日時 2021-03-12 22:01:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,601 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 206,116 KB
実行使用メモリ 18,144 KB
最終ジャッジ日時 2023-08-04 19:02:38
合計ジャッジ時間 4,425 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,288 KB
testcase_01 AC 3 ms
5,140 KB
testcase_02 AC 3 ms
5,444 KB
testcase_03 AC 2 ms
5,412 KB
testcase_04 AC 3 ms
5,340 KB
testcase_05 AC 2 ms
5,340 KB
testcase_06 AC 2 ms
5,204 KB
testcase_07 AC 3 ms
5,252 KB
testcase_08 AC 3 ms
5,304 KB
testcase_09 AC 60 ms
8,284 KB
testcase_10 AC 62 ms
8,280 KB
testcase_11 AC 44 ms
7,536 KB
testcase_12 AC 60 ms
8,092 KB
testcase_13 AC 18 ms
6,292 KB
testcase_14 AC 49 ms
7,788 KB
testcase_15 AC 3 ms
5,288 KB
testcase_16 AC 38 ms
7,376 KB
testcase_17 AC 46 ms
7,520 KB
testcase_18 AC 31 ms
7,128 KB
testcase_19 AC 45 ms
7,304 KB
testcase_20 AC 12 ms
5,912 KB
testcase_21 AC 36 ms
6,960 KB
testcase_22 AC 23 ms
6,172 KB
testcase_23 AC 7 ms
6,228 KB
testcase_24 AC 11 ms
5,908 KB
testcase_25 AC 9 ms
5,684 KB
testcase_26 AC 50 ms
7,664 KB
testcase_27 AC 72 ms
9,748 KB
testcase_28 AC 70 ms
18,144 KB
testcase_29 AC 70 ms
17,784 KB
testcase_30 AC 51 ms
10,620 KB
testcase_31 AC 64 ms
10,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
 ll MOD=1000000007;
 ll MOD9=998244353;
 int inf=1e9+10;
 ll INF=1e18;
 ll dy[8]={1,0,-1,0,1,1,-1,-1};
 ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}
vvl g(100010);
bool ans=true;
ll dim=0;
ll dfs(ll v,ll par=-1){//もっとも遠い頂点の距離
  ll ret=0;
  vl vs;
  for(auto p:g[v]){
    if(p==par)continue;
    vs.push_back(dfs(p,v));
  }
  sort(all(vs));
  if(vs.size())if(*vs.begin()!=*vs.rbegin())ans=false;
  if(vs.size())chmax(ret,vs[0]);
  if(vs.size()>1){
    if(dim==0)dim=ret*2;
    else {
      if(dim!=ret*2)ans=false;
    }
  }
  ret++;
  return ret;
}
int main(){
  ll n;cin >> n;
  rep(i,n-1){
    ll a,b;cin >>a  >> b;a--;b--;
    g[a].pb(b);g[b].pb(a);
  }
  ll s=-1;
  rep(i,n)if(g[i].size()==1)s=i;
  ll p=dfs(s);p--;
  if((ans&&(p==dim))||dim==0)cout << "Yes" <<endl;
  else cout << "No" <<endl;

}
0