結果

問題 No.583 鉄道同好会
ユーザー aaaaaaiuaaaaaaiu
提出日時 2019-08-30 01:29:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,125 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 203,160 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-11 07:26:32
合計ジャッジ時間 4,078 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 13 ms
4,376 KB
testcase_12 AC 17 ms
4,376 KB
testcase_13 AC 17 ms
4,380 KB
testcase_14 AC 17 ms
4,380 KB
testcase_15 AC 22 ms
4,376 KB
testcase_16 AC 39 ms
4,380 KB
testcase_17 AC 47 ms
4,376 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct UF {
    vector<int> par,cnt;
    UF(int n) {
        cnt.resize(n,1);
        for (int i=0;i<n;i++)
            par.push_back(i);
    }
    int find(int a) {
        if (par[a]==a)
            return a;
        return par[a]=find(par[a]);
    }
    void unite(int a,int b) {
        a=find(a);
        b=find(b);
        if (a==b)
            return;
        par[b]=a;
        cnt[a]+=cnt[b];
    }
    int count(int a) {
        a=find(a);
        return cnt[a];
    }
};

int main() {
    int n,m;
    cin>>n>>m;
    UF u(n);
    int edge[n];
    for (int i=0;i<m;i++) {
        int a,b;
        cin>>a>>b;
        edge[a]++;
        edge[b]++;
        u.unite(a,b);
    }
    int cnt=0;
    for (int i=0;i<n;i++) {
        if (u.find(i)==i) {
            if (u.count(i)>1)
                cnt++;
        }
    }
    if (cnt>1) {
        puts("NO");
        return 0;
    }
    int odd=0;
    for (int i=0;i<n;i++)
        if (edge[i]%2)
            odd++;
    if (odd==0||odd==2)
        puts("YES");
    else
        puts("NO");
    return 0;
}
0