結果

問題 No.583 鉄道同好会
ユーザー tottoripapertottoripaper
提出日時 2017-10-27 23:01:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,592 bytes
コンパイル時間 1,633 ms
コンパイル使用メモリ 177,752 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 17:18:40
合計ジャッジ時間 2,331 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 9 ms
6,940 KB
testcase_12 AC 14 ms
6,940 KB
testcase_13 AC 13 ms
6,940 KB
testcase_14 AC 14 ms
6,940 KB
testcase_15 AC 21 ms
6,940 KB
testcase_16 AC 41 ms
6,940 KB
testcase_17 AC 53 ms
6,940 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N, M;
vector<int> G[510];
vector<P> ps;
bool used[510*510], used2[510];

bool f(){
    int odd_n = 0;
    for(int i=0;i<M;++i){
        int a, b;
        tie(a, b) = ps[i];
        if((G[a].size() + G[b].size()) % 2 == 1){
            ++odd_n;
        }
    }

    return odd_n == 0 || odd_n == 2;
}

bool g(){
    for(int i=0;i<M;++i){
        if(!used[i]){
            return false;
        }
    }
    return true;
}

void dfs(int e){
    int a, b;
    tie(a, b) = ps[e];
    
    used[e] = true;
    used2[a] = true;
    used2[b] = true;

    for(int e2 : G[a]){
        int a2, b2;
        tie(a2, b2) = ps[e2];

        if(!used[e2] && !used2[a ^ a2 ^ b2]){
            dfs(e2);
        }
    }

    for(int e2 : G[b]){
        int a2, b2;
        tie(a2, b2) = ps[e2];

        if(!used[e2] && !used2[a ^ a2 ^ b2]){
            dfs(e2);
        }        
    }
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        int a, b;
        std::cin >> a >> b;

        ps.emplace_back(a, b);
        G[a].emplace_back(i);
        G[b].emplace_back(i);
    }

    dfs(0);

    const string YESNO[2] = {"NO", "YES"};
    std::cout << YESNO[(f() && g())] << std::endl;
}
0