結果
| 問題 |
No.583 鉄道同好会
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-27 23:19:00 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 54 ms / 2,000 ms |
| コード長 | 1,431 bytes |
| コンパイル時間 | 500 ms |
| コンパイル使用メモリ | 61,928 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-21 23:15:40 |
| 合計ジャッジ時間 | 1,466 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#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[i][0];
cin >> trains[i][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][1]]) && !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;
}
}