結果

問題 No.583 鉄道同好会
ユーザー ミドリムシミドリムシ
提出日時 2017-10-27 23:13:44
言語 C++11
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 1,431 bytes
コンパイル時間 2,351 ms
コンパイル使用メモリ 61,876 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2024-11-21 23:12:13
合計ジャッジ時間 54,958 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 9 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int trains[M][2];
    for(int i = 0; i < M; i++){
        cin >> trains[M][0];
        cin >> trains[M][1];
    }
    bool if_can_go[N];
    bool if_can_use[M];
    for(int i = 0; i < N; i++){
        if_can_go[i] = false;
    }
    for(int i = 1; i < M; i++){
        if_can_use[i] = false;
    }
    if_can_use[0] = true;
    if_can_go[trains[0][0]] = true;
    if_can_go[trains[0][1]] = true;
    while(true){
        bool if_fin = true;
        for(int i = 0; i < M; i++){
            if((if_can_go[trains[i][0]] || if_can_go[trains[i][0]]) && !if_can_use[i]){
                if_can_go[trains[i][0]] = true;
                if_can_go[trains[i][1]] = true;
                if_can_use[i] = true;
                if_fin = false;
            }
        }
        if(if_fin){
            break;
        }
    }
    for(int i = 0; i < M; i++){
        if(!if_can_use[i]){
            cout << "NO" << endl;
            return 0;
        }
    }
    int stop[N];
    for(int i = 0; i < N; i++){
        stop[i] = 0;
    }
    for(int i = 0; i < M; i++){
        stop[trains[i][0]]++;
        stop[trains[i][1]]++;
    }
    int count = 0;
    for(int i = 0; i < N; i++){
        count += stop[i] % 2;
    }
    if(count <= 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}
0