結果
| 問題 |
No.583 鉄道同好会
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-27 22:51:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 890 bytes |
| コンパイル時間 | 1,527 ms |
| コンパイル使用メモリ | 171,860 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-21 22:42:11 |
| 合計ジャッジ時間 | 2,335 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 13 WA * 3 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
int cnt[500];
class UnionFind {
vector<int>par, high;
public:
UnionFind(int n) {
par = high = vector<int>(n);
for (int i = 0; i < n; i++)par[i] = i;
}
int find(int x) {
if (par[x] == x)return x;
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x); y = find(y);
if (x == y)return;
if (high[x] > high[y])par[y] = x;
else {
par[x] = y;
if (high[x] == high[y])high[y]++;
}
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
int main(){
int n,m;scanf("%d%d",&n,&m);
UnionFind uf(n);
rep(i,m){
int a,b;scanf("%d%d",&a,&b);
cnt[a]++;cnt[b]++;
uf.unite(a,b);
}
int c=0,d=0;
rep(i,n){
if(cnt[i]%2)c++;
else d++;
}
rep(i,n)rep(j,n){
if(!uf.same(i,j)){
puts("NO");return 0;
}
}
if(c==0||c==2)puts("YES");
else puts("NO");
}