結果

問題 No.583 鉄道同好会
ユーザー tottoripapertottoripaper
提出日時 2017-10-27 23:08:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,256 bytes
コンパイル時間 1,568 ms
コンパイル使用メモリ 168,232 KB
実行使用メモリ 4,404 KB
最終ジャッジ日時 2023-08-14 04:48:04
合計ジャッジ時間 2,596 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 18 ms
4,380 KB
testcase_17 AC 21 ms
4,384 KB
testcase_18 AC 21 ms
4,404 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:70:8: 警告: ‘S’ may be used uninitialized [-Wmaybe-uninitialized]
   70 |     dfs(S);
      |     ~~~^~~
main.cpp:56:9: 備考: ‘S’ はここで定義されています
   56 |     int S;
      |         ^

ソースコード

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];
bool used[510], used2[510];

bool f(){
    int odd_n = 0;
    for(int i=0;i<N;++i){
        if(G[i].size() % 2 == 1){
            ++odd_n;
        }
    }

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

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

void dfs(int v){
    used[v] = true;

    for(int w : G[v]){
        if(!used[w]){
            dfs(w);
        }
    }
}

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

    std::cin >> N >> M;

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

        S = a;
        
        G[a].emplace_back(b);
        G[b].emplace_back(a);

        used2[a] = true;
        used2[b] = true;
    }

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