結果
| 問題 |
No.583 鉄道同好会
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-07 15:45:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 1,990 bytes |
| コンパイル時間 | 1,014 ms |
| コンパイル使用メモリ | 98,400 KB |
| 実行使用メモリ | 5,484 KB |
| 最終ジャッジ日時 | 2024-11-24 04:46:39 |
| 合計ジャッジ時間 | 1,723 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;
#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll station[501];
struct UnionFind {
vector<int> node;
UnionFind(int n) : node(n,-1) {}
bool unite(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (node[y] < node[x]) swap(x, y);
node[x] += node[y];
node[y] = x;
}
return x != y;
}
bool same(int x, int y) {
return root(x) == root(y);
}
int root(int x) {
return node[x] < 0 ? x : node[x] = root(node[x]);
}
int size(int x) {
return -node[root(x)];
}
};
void operat(ll a){
if(station[a]==0) station[a]=1;
else station[a]=0;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll N , M;
cin >> N >> M;
UnionFind road(501);
vector<ll> direction;
rep(i,M){
ll a, b; cin >> a >> b;
operat(a);
operat(b);
road.unite(a,b);
direction.pb(a);
direction.pb(b);
}
ll ans = 0;
rep(i,501){
if(station[i]!=0) ans ++;
}
ll R = road.root(direction[0]);
rep(i,direction.size()-1){
if(road.root(direction[i+1]) != R){
cout << "NO" << endl;
return 0;
}
}
if(ans == 2 || ans == 0) cout << "YES" << endl;
else cout << "NO" << endl;
//cout << fixed << setprecision(16) << ans << endl;
return 0;
}