結果

問題 No.1424 Ultrapalindrome
ユーザー ocvret_ocvret_
提出日時 2021-03-12 22:15:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,141 bytes
コンパイル時間 1,943 ms
コンパイル使用メモリ 171,136 KB
実行使用メモリ 16,896 KB
最終ジャッジ日時 2024-04-22 13:17:06
合計ジャッジ時間 3,842 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,832 KB
testcase_01 AC 5 ms
8,576 KB
testcase_02 AC 6 ms
8,832 KB
testcase_03 AC 6 ms
8,704 KB
testcase_04 AC 5 ms
8,704 KB
testcase_05 AC 5 ms
8,832 KB
testcase_06 AC 5 ms
8,704 KB
testcase_07 AC 5 ms
8,832 KB
testcase_08 WA -
testcase_09 AC 66 ms
11,904 KB
testcase_10 AC 67 ms
11,904 KB
testcase_11 AC 47 ms
10,880 KB
testcase_12 AC 62 ms
11,776 KB
testcase_13 AC 21 ms
9,472 KB
testcase_14 AC 50 ms
11,264 KB
testcase_15 AC 6 ms
8,832 KB
testcase_16 AC 40 ms
10,624 KB
testcase_17 AC 47 ms
11,008 KB
testcase_18 AC 33 ms
10,240 KB
testcase_19 AC 54 ms
10,880 KB
testcase_20 AC 16 ms
9,216 KB
testcase_21 AC 43 ms
10,496 KB
testcase_22 AC 30 ms
9,728 KB
testcase_23 AC 10 ms
9,088 KB
testcase_24 AC 15 ms
9,216 KB
testcase_25 AC 15 ms
9,088 KB
testcase_26 AC 65 ms
11,136 KB
testcase_27 WA -
testcase_28 AC 73 ms
16,896 KB
testcase_29 AC 74 ms
16,896 KB
testcase_30 AC 60 ms
13,548 KB
testcase_31 AC 69 ms
13,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


vector<int> d;
void dfs(vector<vector<int>> &v,int ov){
  for(auto nv : v[ov]){
    if(d[nv] != -1)continue;
    d[nv] = d[ov] + 1;
    dfs(v,nv);
  }
}

int n;
vector<int> deg(200000);
vector<vector<int>> v(200000);

bool solve(int root){
  d.assign(n,-1);
  d[root] = 0;
  dfs(v,root);
  vector<int> w;
  rep(i,n)if(deg[i] == 1 && i != root)w.push_back(d[i]);
  sort(ALL(w));
  return w[0] == w.back();
}

int main(){
  
  cin >> n;
  rep(i,n-1){
    int a,b;cin >> a >> b;
    a--;b--;
    deg[a]++;deg[b]++;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int cnt = 0;
  rep(i,n){
    if(deg[i] == 1){
      if(!solve(i)){
        cout << "No\n";
        return 0;
      }else cnt++;
    }
    if(cnt == 2)break;
  }
  cout << "Yes\n";
  


  return 0;
}
0