提出 #38218695


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ld = long double;
using pll = pair<ll, ll>;
// and so on
int par[200001];
int fnd(int x){
    return par[x]? par[x] = fnd(par[x]) : x;
}
bool uni(int a, int b){
    a = fnd(a);
    b = fnd(b);
    if(a != b){
        par[b] = a;
        return true;
    }
    return false;
}
pii edges[200001];
bool chk[200001];
int cnt[200001];
bool vis2[200001];
bool vis[200001];
vector<vector<int> > mp;
void dfs(int x){
    vis[x] = true;
    for(int nx : mp[x]){
        if(!vis[nx]) dfs(nx);
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N, M;
    cin>>N>>M;
    mp.resize(N+1);
    for(int i=1;i<=M;i++){
        int a, b;
        cin>>a>>b;
        edges[i] = {a, b};
    }
    int K;
    cin>>K;
    for(int i=0;i<K;i++){
        int x;
        cin>>x;
        chk[x] = true;
    }
    for(int i=1;i<=M;i++){
        if(!chk[i]){
            auto [a, b] = edges[i];
            uni(a, b);
        }
    }
    for(int i=1;i<=M;i++){
        if(chk[i]){
            auto [a, b] = edges[i];
            a = fnd(a);
            b = fnd(b);
            vis2[a] = true;
            vis2[b] = true;
            if(a != b){
                cnt[a]++;
                cnt[b]++;
                mp[a].push_back(b);
                mp[b].push_back(a);
            }
        }
    }
    dfs(fnd(1));
    bool isok = true;
    int left = 0;
    for(int i=1;i<=N;i++){
        if(vis2[i]){
            isok &= vis[i];
            left += cnt[i]%2;
        }
    }
    isok &= left == 0 || left == 2;
    cout<<(isok?"Yes":"No"); 
}

提出情報

提出日時
問題 G - Unique Walk
ユーザ jame0313
言語 C++ (GCC 9.2.1)
得点 600
コード長 1727 Byte
結果 AC
実行時間 102 ms
メモリ 23216 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 2
AC × 53
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, random2_00.txt, random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random2_06.txt, random2_07.txt, random2_08.txt, random2_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 4 ms 3564 KiB
example_01.txt AC 2 ms 3560 KiB
hand_00.txt AC 102 ms 23216 KiB
hand_01.txt AC 55 ms 12576 KiB
hand_02.txt AC 54 ms 12892 KiB
hand_03.txt AC 71 ms 17800 KiB
hand_04.txt AC 100 ms 20832 KiB
hand_05.txt AC 98 ms 20572 KiB
hand_06.txt AC 98 ms 21140 KiB
hand_07.txt AC 26 ms 5168 KiB
hand_08.txt AC 24 ms 5188 KiB
hand_09.txt AC 30 ms 5264 KiB
hand_10.txt AC 28 ms 5264 KiB
random2_00.txt AC 55 ms 8660 KiB
random2_01.txt AC 56 ms 8592 KiB
random2_02.txt AC 45 ms 5976 KiB
random2_03.txt AC 47 ms 6080 KiB
random2_04.txt AC 49 ms 7844 KiB
random2_05.txt AC 51 ms 7640 KiB
random2_06.txt AC 52 ms 8072 KiB
random2_07.txt AC 58 ms 11132 KiB
random2_08.txt AC 49 ms 6476 KiB
random2_09.txt AC 57 ms 7560 KiB
random_00.txt AC 51 ms 10028 KiB
random_01.txt AC 43 ms 8544 KiB
random_02.txt AC 46 ms 9636 KiB
random_03.txt AC 49 ms 9128 KiB
random_04.txt AC 47 ms 9328 KiB
random_05.txt AC 47 ms 9140 KiB
random_06.txt AC 19 ms 5184 KiB
random_07.txt AC 44 ms 7276 KiB
random_08.txt AC 44 ms 7168 KiB
random_09.txt AC 40 ms 7512 KiB
random_10.txt AC 45 ms 6424 KiB
random_11.txt AC 43 ms 6744 KiB
random_12.txt AC 71 ms 14788 KiB
random_13.txt AC 43 ms 10648 KiB
random_14.txt AC 43 ms 11172 KiB
random_15.txt AC 57 ms 12584 KiB
random_16.txt AC 45 ms 10612 KiB
random_17.txt AC 44 ms 11516 KiB
random_18.txt AC 42 ms 7424 KiB
random_19.txt AC 41 ms 5904 KiB
random_20.txt AC 39 ms 5684 KiB
random_21.txt AC 34 ms 5996 KiB
random_22.txt AC 38 ms 6124 KiB
random_23.txt AC 42 ms 6592 KiB
random_24.txt AC 48 ms 9440 KiB
random_25.txt AC 43 ms 8708 KiB
random_26.txt AC 47 ms 9408 KiB
random_27.txt AC 36 ms 8088 KiB
random_28.txt AC 41 ms 7688 KiB
random_29.txt AC 45 ms 11500 KiB