結果

問題 No.583 鉄道同好会
ユーザー imulanimulan
提出日時 2018-01-07 03:28:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,270 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 177,432 KB
実行使用メモリ 4,400 KB
最終ジャッジ日時 2023-08-24 23:00:00
合計ジャッジ時間 3,444 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 500;
vector<int> G[N];

string solve(){
    int n,m;
    cin >>n >>m;

    set<int> s;
    rep(i,m){
        int u,v;
        cin >>u >>v;
        s.insert(u);
        s.insert(v);
        G[u].pb(v);
        G[v].pb(u);
    }

    int start = *s.begin();
    vector<bool> vis(n);
    queue<int> que;
    vis[start] = true;
    que.push(start);
    while(!que.empty()){
        int now=que.front();
        que.pop();
        for(int e:G[now]){
            if(!vis[e]){
                vis[e]=true;
                que.push(e);
            }
        }
    }

    int odd = 0;
    for(int i:s){
        if(!vis[i]) return "NO";
        odd += (G[i].size()%2);
    }

    return (odd==0||odd==2)?"YES":"NO";
}

int main(){
    cout << solve() << endl;
    return 0;
}
0