結果

問題 No.583 鉄道同好会
ユーザー mtsdmtsd
提出日時 2017-10-27 22:39:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,261 bytes
コンパイル時間 685 ms
コンパイル使用メモリ 81,184 KB
実行使用メモリ 4,720 KB
最終ジャッジ日時 2023-08-14 04:24:34
合計ジャッジ時間 1,907 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 18 ms
4,380 KB
testcase_12 AC 25 ms
4,380 KB
testcase_13 AC 24 ms
4,376 KB
testcase_14 AC 25 ms
4,380 KB
testcase_15 AC 31 ms
4,384 KB
testcase_16 AC 58 ms
4,720 KB
testcase_17 AC 68 ms
4,584 KB
testcase_18 AC 70 ms
4,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007

long long  mod = 1000000007;

int p[2000];

void init(int n){
    for (int i = 0; i < n; ++i) {
        p[i]=i;
    }
}


int find(int x){
	if(x != p[x]){
		p[x] = find(p[x]);
    	}
    	return p[x];
    }
     
void union_set(int x,int y){
	x = find(x);
	y = find(y);
	if(x==y) return;
	p[x]=y;
	return ;
}


int main(){
	int n,m;
	cin >> n >> m;
	vector<vector<int> >v(n);
	set<int> st;
	init(n);
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
		union_set(a,b);
		st.insert(a);
		st.insert(b);
	}
	int x = 0;
	for(int i=0;i<n;i++){
		if(v[i].size()%2==1)x++;
	}
	if(x>=3){
		cout << "NO" << endl;
		return 0;
	}
	int z = -1;
	bool flag = 0;
	for(int i=0;i<n;i++){
		if(v[i].size()!=0){
			if(z==-1){
				z = find(i);
			}else{
				if(z!=find(i)){
					flag = 1;
				}
			}
		}
	}
	if(flag){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
	return 0;
}
0