結果

問題 No.1424 Ultrapalindrome
ユーザー dekomori_sanaedekomori_sanae
提出日時 2021-03-12 21:39:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,862 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 94,652 KB
実行使用メモリ 12,804 KB
最終ジャッジ日時 2024-04-22 12:27:36
合計ジャッジ時間 3,180 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
6,944 KB
testcase_08 WA -
testcase_09 AC 70 ms
10,240 KB
testcase_10 AC 64 ms
10,368 KB
testcase_11 AC 46 ms
8,192 KB
testcase_12 AC 61 ms
9,856 KB
testcase_13 AC 17 ms
6,940 KB
testcase_14 AC 48 ms
8,704 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 41 ms
7,808 KB
testcase_17 AC 48 ms
8,448 KB
testcase_18 AC 32 ms
6,940 KB
testcase_19 AC 48 ms
8,576 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 6 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 69 ms
11,776 KB
testcase_29 WA -
testcase_30 AC 57 ms
12,804 KB
testcase_31 AC 68 ms
12,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

struct Edge {
    ll to, cost;
    Edge(ll to, ll cost): to(to), cost(cost) {}
};

int main() {
    ll n;
    cin >> n;
    
    vector<vector<Edge>> G(n);
    vl deg(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].emplace_back(b, 1);
        G[b].emplace_back(a, 1);
        deg[a]++;  deg[b]++;
    }
    
    vl dist(n, -1);  // dist[v] : 頂点vの根からの距離
    queue<ll> Q;
    const ll root = 0;
    dist[root] = 0;
    Q.push(root);
    while(!Q.empty()) {
        ll v = Q.front();  Q.pop();
        for(Edge e : G[v]) {
            if(dist[e.to] == -1) {
                dist[e.to] = dist[v] + e.cost;
                Q.push(e.to);
            }
        }
    }
    
    bool ok = true;
    ll x = -1;
    rep(v, n) {
        if(v != root && deg[v] == 1) {
            if(x == -1) {
                x = dist[v];
            }
            else if(x != dist[v]) {
                ok = false;
            }
        }
    }

    if(ok) {
        out("Yes");
    }
    else {
        out("No");
    }
    
    re0;
}
0