結果

問題 No.583 鉄道同好会
ユーザー ミドリムシミドリムシ
提出日時 2017-10-27 23:13:44
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,431 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 62,352 KB
実行使用メモリ 14,008 KB
最終ジャッジ日時 2024-05-01 17:40:08
合計ジャッジ時間 7,685 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

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