結果

問題 No.583 鉄道同好会
ユーザー homesentinelhomesentinel
提出日時 2017-10-27 23:09:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 3,252 bytes
コンパイル時間 1,342 ms
コンパイル使用メモリ 109,096 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 04:48:35
合計ジャッジ時間 2,561 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する
class UnionFind {
    vector<int> p;//p[i]はiの属する組織
public:
    UnionFind(int n) {
        p = vector<int>(n);
        for (int i = 0; i < n; i++) {
            p[i] = i;
        }
        return;
    }

    void printState() {
        if (DEBUG) {
            cout << "---" << endl;
            for (int i = 0; i < p.size(); i++) {
                printf("%dの親は%d\n", i, p[i]);
            }
            cout << "---" << endl;
        }
    }

/* xの属する集合を返す */
    int find(int x) {
        if (p[x] == x) return x;
        return p[x] = find(p[x]);
    }

/* yにxを統合する */
    void unite(int x, int y) {
        p[find(x)] = p[find(y)];
    }

/* xとyが属する集合が同じかを判定する */
    bool same(int x, int y) {
        return find(x) == find(y);
    }

};


int main() {
    int N, M;
    cin >> N >> M;
    vector<int> dim(N, 0);
    vector<int> a(M), b(M);
//    vector<bool> used(N,false);
    set<int> use;
    UnionFind u(N);
    REP(i, 0, M) {
        cin >> a[i] >> b[i];
        dim[a[i]]++;
        dim[b[i]]++;
        u.unite(a[i], b[i]);
//        used[a[i]] = true;
//        used[b[i]] = true;
        use.insert(a[i]);
        use.insert(b[i]);
    }


//    REP(i,0,M){
//        REP(j,0,M){
//            if(i != j){
//                if(!u.same(a[i],a[j])){
//                    cout << "NO" << endl;
//                    return 0;
//                }
//            }
//        }
//    }
    for (auto it = use.begin(); it != use.end(); it++) {
        if (it == use.begin()) continue;
        auto jt = --it;
        it++;
        if (!u.same(*jt, *it)) {
            cout << "NO" << endl;
            return 0;
        }
    }


    int cnt = 0;
    REP(i, 0, N) {
        if (dim[i] % 2 == 1) {
            cnt++;
        }
    }
    if (cnt == 0 || cnt == 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}
0