結果
| 問題 | No.583 鉄道同好会 | 
| コンテスト | |
| ユーザー |  tottoripaper | 
| 提出日時 | 2017-10-27 23:08:17 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 22 ms / 2,000 ms | 
| コード長 | 1,256 bytes | 
| コンパイル時間 | 1,760 ms | 
| コンパイル使用メモリ | 171,080 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-21 23:02:51 | 
| 合計ジャッジ時間 | 2,727 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:70:8: warning: 'S' may be used uninitialized [-Wmaybe-uninitialized]
   70 |     dfs(S);
      |     ~~~^~~
main.cpp:56:9: note: 'S' was declared here
   56 |     int S;
      |         ^
            
            ソースコード
#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;
}
            
            
            
        