結果
| 問題 | No.583 鉄道同好会 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-17 18:13:55 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,855 bytes |
| 記録 | |
| コンパイル時間 | 905 ms |
| コンパイル使用メモリ | 98,528 KB |
| 実行使用メモリ | 8,704 KB |
| 最終ジャッジ日時 | 2024-06-22 06:44:01 |
| 合計ジャッジ時間 | 2,631 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 WA * 1 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vii = vector<vi>;
using vl = vector<ll>; using vll = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
struct UFT{
vector<int> par;//親
vector<int> rank;//木の深さ
vector<int> size;//木の大きさ
int n;
UFT(int _n)
{
n = _n;
par.resize(n);
rank.assign(n,0);
size.assign(n,0);
rep(i,n){
par[i] = i;
}
}
//xの根を返す
int find(int x)
{
if(par[x] == x) return x;
else return par[x] = find(par[x]);
}
//x,yを併合
void unite(int x,int y)
{
x = find(x);
y = find(y);
if(x == y) return;
if(rank[x] < rank[y]){
par[x] = y;
size[y] += size[x];
}
else{
par[y] = x;
size[x] += size[y];
if(rank[x] == rank[y]) rank[x]++;
}
}
//x,yが同じグループにいるかどうかを返す
bool same(int x,int y)
{
return find(x) == find(y);
}
//xの属する木のサイズを探す
int usize(int x)
{
return size[find(x)];
}
};
//****************************************
// Graph template
//****************************************
// status of edge
template <typename X>
struct Edge{
int from;
int to;
X cost;
Edge() = default;
Edge(int from, int to, X cost) : from(from), to(to), cost(cost) {}
};
// status of node
template <typename X>
struct Node{
int idx;
vector<Edge<X>> edge;
Node() = default;
explicit Node(int idx) : idx(idx) {}
};
template <typename X>
class Graph{
private:
int n; // number of node
int m; // number of edge
vector<Node<X>> node;
void Init_Node() {
rep(i,n) node.emplace_back(i);
}
public:
explicit Graph(int n) : n(n) {
Init_Node();
}
// edges have no-weight
Graph(int n, int m, vector<int> from, vector<int> to) : n(n), m(m) {
Init_Node();
rep(i,m) {
add_edge(from[i], to[i]);
add_edge(to[i], from[i]);
}
}
// edges have weight
Graph(int n, int m, vector<int> from, vector<int> to, vector<X> cost) : n(n), m(m) {
Init_Node();
rep(i,m) {
add_edge(from[i], to[i], cost[i]);
add_edge(to[i], from[i], cost[i]);
}
}
void add_edge(int from, int to, X cost = 1) {
node[from].edge.emplace_back(from, to, cost);
}
// オイラー閉路があるか?
bool EulerCheck() {
bool res = true;
rep(i,n) {
int a = node[i].edge.size();
if(a % 2 == 1) res = false;
}
return res;
}
// s->tのオイラー路があるか?
bool EulerCheck(int s, int t) {
bool res = true;
rep(i,n) {
if(i == s || i == t) continue;
int a = node[i].edge.size();
if(a % 2 == 1) res = false;
}
return res;
}
};
int main()
{
int n,m; cin >> n >> m;
vi a(m), b(m);
UFT uf(n);
vector<bool> f(n, false);
rep(i,m) {
cin >> a[i] >> b[i];
uf.unite(a[i], b[i]);
f[a[i]] = f[b[i]] = true;
}
Graph<int> gp(n, m, a, b);
rep(i,n) {
rep(j,n) {
if(i >= j) continue;
if( !f[i] || !f[j] ) continue;
if( !uf.same(i, j) ) {
cout << "NO" << "\n";
return 0;
}
if(gp.EulerCheck(i, j)) {
cout << "YES" << "\n";
return 0;
}
}
}
cout << "NO" << "\n";
return 0;
}