結果
| 問題 | No.583 鉄道同好会 | 
| コンテスト | |
| ユーザー |  aaaaa | 
| 提出日時 | 2017-10-31 01:38:05 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 55 ms / 2,000 ms | 
| コード長 | 1,355 bytes | 
| コンパイル時間 | 796 ms | 
| コンパイル使用メモリ | 76,636 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-22 11:08:50 | 
| 合計ジャッジ時間 | 1,744 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
ソースコード
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;
int main(){
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	
	int n,m;
	cin>>n>>m;
	vector<vector<int>> s(n);
	int a,b;
	rep(i,m){
		cin>>a>>b;
		s[a].push_back(b);
		s[b].push_back(a);
	}
	//連結
	vector<int> check(n);
	rep(i,n){
		check[i]=-1;
	}
	a=0;
	b=0;
	int aa=1;
	while(aa){
		stack<int> sta;
		sta.push(a);
		check[a]=b;
		while(sta.empty()==0){
			int x=sta.top();
			sta.pop();
			rep(i,s[x].size()){
				if(check[s[x][i]]==-1){
					sta.push(s[x][i]);
					check[s[x][i]]=b;
				}
			}
		}
		b++;
		rep(i,n){
			if(check[i]==-1){
				a=i;
				break;
			}
			if(i==n-1){
				aa=0;
			}
		}
	}
	vector<int> y(n);
	rep(i,n){
		y[i]=0;
	}
	rep(i,n){
		y[check[i]]++;
	}
	int z=0;
	rep(i,y.size()){
		if(y[i]>1 && z==0){
			z=1;
		}else if(y[i]>1 && z==1){
			cout<<"NO"<<endl;
			return 0;	
		}
	}
	int cc=0;
	rep(i,n){
		if(s[i].size()%2==1){
			cc++;
		}
	}
	if(cc>2){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
}
            
            
            
        