結果

問題 No.1424 Ultrapalindrome
ユーザー norikamenorikame
提出日時 2021-03-12 23:38:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,102 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 202,904 KB
実行使用メモリ 10,616 KB
最終ジャッジ日時 2024-04-22 15:02:50
合計ジャッジ時間 4,607 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 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 75 ms
8,320 KB
testcase_10 AC 74 ms
8,320 KB
testcase_11 AC 52 ms
6,784 KB
testcase_12 AC 70 ms
7,936 KB
testcase_13 AC 17 ms
5,376 KB
testcase_14 AC 56 ms
7,040 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 43 ms
6,272 KB
testcase_17 AC 51 ms
6,912 KB
testcase_18 AC 34 ms
5,632 KB
testcase_19 AC 55 ms
6,656 KB
testcase_20 AC 13 ms
5,376 KB
testcase_21 AC 43 ms
5,760 KB
testcase_22 AC 25 ms
5,376 KB
testcase_23 AC 6 ms
5,376 KB
testcase_24 AC 12 ms
5,376 KB
testcase_25 AC 11 ms
5,376 KB
testcase_26 AC 66 ms
7,296 KB
testcase_27 WA -
testcase_28 AC 70 ms
9,088 KB
testcase_29 WA -
testcase_30 AC 58 ms
10,616 KB
testcase_31 AC 72 ms
10,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
#define v(t) vector<t>
#define p(t) pair<t, t>
#define p2(t, s) pair<t, s>
#define vp(t) v(p(t))

#define rep(i, n) for (int i=0,i##_len=((int)(n)); i<i##_len; ++i)
#define rep2(i, a, n) for (int i=((int)(a)),i##_len=((int)(n)); i<=i##_len; ++i)
#define repr(i, n) for (int i=((int)(n)-1); i>=0; --i)
#define rep2r(i, a, n) for (int i=((int)(n)),i##_len=((int)(a)); i>=i##_len; --i)

#define repi(itr, c) for (__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); ++itr)
#define repir(itr, c) for (__typeof((c).rbegin()) itr=(c).rbegin(); itr!=(c).rend(); ++itr)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define eb emplace_back

#define INF (1e9)
#define LINF (1e18)
#define PI (acos(-1))
#define EPS (1e-7)
#define DEPS (1e-10)

int main(){
    int n;
    cin >> n;
    v(v(int)) g(n);
    rep(i, n-1) {
        int ai, bi;
        cin >> ai >> bi;
        --ai; --bi;
        g[ai].pb(bi);
        g[bi].pb(ai);
    }
    bool ok = false;
    rep(i, n) {
        if (sz(g[i]) > 1) continue;
        queue<int> que;
        v(int) dist(n, (int)(INF));
        que.push(i);
        dist[i] = 0;
        v(int) leaf;
        while (!que.empty()) {
            int pi = que.front(); que.pop();
            int d = dist[pi], nd = d+1;
            if (sz(g[pi])==1 && pi!=i) leaf.pb(d);
            rep(j, sz(g[pi])) {
                int to = g[pi][j];
                if (dist[to] <= nd) continue;
                que.push(to);
                dist[to] = nd;
            }
        }
        bool ok2 = true;
        if (sz(leaf) >= 2) { rep(j, sz(leaf)-1) if (leaf[j] != leaf[j+1]) ok2 = false; }
        if (ok2) ok = true;
        break;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
0