結果

問題 No.1424 Ultrapalindrome
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-19 18:27:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,448 bytes
コンパイル時間 4,385 ms
コンパイル使用メモリ 206,336 KB
実行使用メモリ 10,708 KB
最終ジャッジ日時 2023-09-09 13:53:34
合計ジャッジ時間 6,231 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 65 ms
7,584 KB
testcase_10 AC 62 ms
7,848 KB
testcase_11 AC 43 ms
6,220 KB
testcase_12 AC 60 ms
7,264 KB
testcase_13 AC 17 ms
4,380 KB
testcase_14 AC 50 ms
6,860 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 37 ms
5,948 KB
testcase_17 AC 47 ms
6,432 KB
testcase_18 AC 32 ms
5,680 KB
testcase_19 AC 48 ms
6,736 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 38 ms
6,020 KB
testcase_22 AC 24 ms
4,888 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 11 ms
4,376 KB
testcase_25 AC 10 ms
4,380 KB
testcase_26 AC 56 ms
7,328 KB
testcase_27 AC 81 ms
9,164 KB
testcase_28 AC 66 ms
8,808 KB
testcase_29 AC 67 ms
9,380 KB
testcase_30 AC 54 ms
10,708 KB
testcase_31 AC 65 ms
10,580 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:74:37: 警告: ‘d’ may be used uninitialized [-Wmaybe-uninitialized]
   74 |     cout << (cnt == d ? "Yes" : "No") << endl;
      |                                     ^
main.cpp:31:33: 備考: ‘d’ はここで定義されています
   31 |     int N, a, b, cnt=0, cnt2=0, d, e;
      |                                 ^
main.cpp:61:32: 警告: ‘e’ may be used uninitialized [-Wmaybe-uninitialized]
   61 |     vector<int> dist = bfs(E, e);
      |                                ^
main.cpp:31:36: 備考: ‘e’ はここで定義されています
   31 |     int N, a, b, cnt=0, cnt2=0, d, e;
      |                                    ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<int> bfs(vector<vector<int>> &E, int start){

    int N = E.size();
    int from, to;
    queue<int> que;
    vector<int> dist(N, 1e9);

    dist[start] = 0;
    que.push(start);

    while(!que.empty()){
        from = que.front();
        que.pop();
        for (auto to : E[from]){
            if (dist[to] != 1e9) continue;
            dist[to] = dist[from] + 1;
            que.push(to);
        }
    }

    return dist;
}

int main(){

    int N, a, b, cnt=0, cnt2=0, d, e;
    cin >> N;
    vector<int> deg(N);
    vector<vector<int>> E(N);
    for (int i=0; i<N-1; i++){
        cin >> a >> b; a--; b--;
        deg[a]++;
        deg[b]++;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    for (int i=0; i<N; i++){
        if (deg[i] == 1) cnt++;
        else if (deg[i] >= 3){
            cnt2++;
            d = deg[i];
            e = i;
        }
    }

    if (cnt == 2){
        cout << "Yes" << endl;
        return 0;
    }
    else if (cnt2 > 1){
        cout << "No" << endl;
        return 0;
    }

    vector<int> dist = bfs(E, e);
    vector<int> v;
    for (int i=0; i<N; i++){
        if (deg[i] == 1) v.push_back(dist[i]);
    }

    for (int i=0; i<v.size(); i++){
        if (v[i] != v[0]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << (cnt == d ? "Yes" : "No") << endl;

    return 0;
}
0