結果

問題 No.1424 Ultrapalindrome
ユーザー ShibuyapShibuyap
提出日時 2021-05-03 23:00:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,343 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 204,012 KB
実行使用メモリ 12,264 KB
最終ジャッジ日時 2023-09-29 19:09:37
合計ジャッジ時間 6,195 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,100 KB
testcase_01 AC 5 ms
8,312 KB
testcase_02 AC 4 ms
8,216 KB
testcase_03 AC 4 ms
8,040 KB
testcase_04 AC 4 ms
8,044 KB
testcase_05 AC 4 ms
8,184 KB
testcase_06 AC 5 ms
8,048 KB
testcase_07 AC 4 ms
8,188 KB
testcase_08 AC 4 ms
8,008 KB
testcase_09 AC 62 ms
10,528 KB
testcase_10 AC 63 ms
10,548 KB
testcase_11 AC 44 ms
9,800 KB
testcase_12 AC 57 ms
10,364 KB
testcase_13 AC 18 ms
8,676 KB
testcase_14 AC 49 ms
10,040 KB
testcase_15 AC 5 ms
8,192 KB
testcase_16 AC 39 ms
9,696 KB
testcase_17 AC 43 ms
9,868 KB
testcase_18 AC 30 ms
9,664 KB
testcase_19 AC 47 ms
10,100 KB
testcase_20 AC 14 ms
8,624 KB
testcase_21 AC 37 ms
9,684 KB
testcase_22 AC 25 ms
9,068 KB
testcase_23 AC 9 ms
8,316 KB
testcase_24 AC 13 ms
8,504 KB
testcase_25 AC 12 ms
8,532 KB
testcase_26 AC 55 ms
10,524 KB
testcase_27 AC 74 ms
11,152 KB
testcase_28 AC 67 ms
11,240 KB
testcase_29 AC 68 ms
11,556 KB
testcase_30 AC 54 ms
12,264 KB
testcase_31 AC 65 ms
11,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005
vector<int> G[MAX_N];
int main() {
    int n;
    cin >> n;
    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int r = -1;
    rep(i,n){
        if(G[i].size() >= 3){
            if(r != -1){
                cout << "No" << endl;
                return 0;
            }
            r = i;
        }
    }
    if(r == -1){
        cout << "Yes" << endl;
        return 0;
    }
    int f[n] = {};
    rep(i,n) f[i] = -1;
    f[r] = 0;
    int h = -1;
    queue<int> que;
    que.push(r);
    while(que.size()){
        int x = que.front();
        que.pop();
        rep(i,G[x].size()){
            int y = G[x][i];
            if(f[y] != -1) continue;
            f[y] = f[x] + 1;
            que.push(y);
        } 
        if(G[x].size() == 1){
            if(h == -1) h = f[x];
            if(f[x] != h){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}
 
 
0