結果
| 問題 |
No.583 鉄道同好会
|
| コンテスト | |
| ユーザー |
mtsd
|
| 提出日時 | 2017-10-27 22:39:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 68 ms / 2,000 ms |
| コード長 | 1,261 bytes |
| コンパイル時間 | 813 ms |
| コンパイル使用メモリ | 82,744 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-21 22:32:38 |
| 合計ジャッジ時間 | 1,861 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#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;
}
mtsd