結果

問題 No.1424 Ultrapalindrome
ユーザー lasjg72lasjg72
提出日時 2021-03-12 23:39:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,387 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 95,328 KB
実行使用メモリ 11,092 KB
最終ジャッジ日時 2024-04-22 15:03:40
合計ジャッジ時間 3,553 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 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 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 65 ms
8,960 KB
testcase_10 AC 64 ms
8,704 KB
testcase_11 AC 44 ms
7,040 KB
testcase_12 AC 62 ms
8,576 KB
testcase_13 AC 17 ms
5,376 KB
testcase_14 AC 50 ms
7,424 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 40 ms
6,784 KB
testcase_17 AC 49 ms
7,296 KB
testcase_18 AC 31 ms
6,016 KB
testcase_19 AC 47 ms
6,940 KB
testcase_20 AC 12 ms
5,376 KB
testcase_21 AC 37 ms
6,272 KB
testcase_22 AC 24 ms
5,376 KB
testcase_23 AC 6 ms
5,376 KB
testcase_24 AC 11 ms
5,376 KB
testcase_25 AC 10 ms
5,376 KB
testcase_26 AC 56 ms
7,552 KB
testcase_27 WA -
testcase_28 AC 70 ms
9,472 KB
testcase_29 AC 71 ms
9,472 KB
testcase_30 AC 58 ms
11,092 KB
testcase_31 AC 71 ms
11,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

struct edge{
    int from;
    int to;
    int co;
};

int main()
{
   int n;
   cin >> n;
   vector<vector<int>> g(n);
   vector<ll> cost(n, 1001001001);
   vector<bool> stamp(n, false);
   for(int i = 0; i < n-1; i++){
       int a, b;
       cin >> a >> b;
       a--; b--;
       g[a].push_back(b);
       g[b].push_back(a);
   }
   int si = 0;
   int tar = 0;
   for(int i = 0; i < n; i++){
       if(si <= g[i].size()){
           si = g[i].size();
           tar = i;
       }
   }
   if(si <= 2){
       cout << "Yes" << endl;
       return 0;
   }
   //cout << tar << endl;
   queue<int> q;
   q.push(tar);
   cost[tar] = 0;
   vector<ll> ans;
   stamp[tar] = true;
   while(!q.empty()){
       int u = q.front(); q.pop();
       for(int v: g[u]){
           if(stamp[v] == true) continue;
           else stamp[v] = true;
            cost[v] = cost[u]+1;
           if(g[v].size() == 1) ans.push_back(cost[v]);
           else q.push(v);
       }
   }
   ll tmp = ans[0];
   for(ll now : ans){
       //cout << now << endl;
       if(tmp != now){
           cout << "No" << endl;
           return 0;
       }
   }
   cout << "Yes" << endl;
   return 0;
}
0