結果

問題 No.583 鉄道同好会
ユーザー ngtkanangtkana
提出日時 2020-04-04 18:33:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,056 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 205,808 KB
実行使用メモリ 5,624 KB
最終ジャッジ日時 2023-09-16 06:04:01
合計ジャッジ時間 3,330 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 9 ms
4,428 KB
testcase_13 AC 10 ms
4,460 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 11 ms
4,400 KB
testcase_16 AC 20 ms
5,560 KB
testcase_17 AC 23 ms
5,480 KB
testcase_18 AC 24 ms
5,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using lint=long long;
using lubl=long double;
#define ALL(v) std::begin(v),std::end(v)
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,m;std::cin>>n>>m;
    std::vector<std::vector<lint>>g(n);
    while(m--){
        lint x,y;std::cin>>x>>y;
        g.at(x).push_back(y);
        g.at(y).push_back(x);
    }
    if(2<std::count_if(ALL(g),[](auto&&v){return v.size()%2==1u;})){
        std::cout<<"NO"<<'\n';
        return 0;
    }
    std::vector<lint>size(n),ckd(n,false),que;
    for(lint i=0,j=0;i<n;i++){
        if(std::exchange(ckd.at(i),true))continue;
        que.push_back(i);
        for(;j<(lint)que.size();j++){
            lint x=que.at(j);
            size.at(i)++;
            for(lint y:g.at(x)){
                if(std::exchange(ckd.at(y),true))continue;
                que.push_back(y);
            }
        }
    }
    std::cout<<(std::count_if(ALL(size),[](lint x){return 1<x;})<=1?"YES":"NO")<<'\n';
}
0