結果
| 問題 |
No.583 鉄道同好会
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-27 22:59:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 1,336 bytes |
| コンパイル時間 | 1,236 ms |
| コンパイル使用メモリ | 97,020 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-21 22:36:30 |
| 合計ジャッジ時間 | 1,915 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;
const int N = 512;
VI edges[N];
bool vis[N];
void dfs(int v) {
if (vis[v]) {
return;
}
vis[v] = true;
REP(i, 0, edges[v].size()) {
int w = edges[v][i];
dfs(w);
}
}
void fail(void) {
cout << "NO\n";
exit(0);
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
VI deg(n);
int start = -1;
REP(i, 0, m) {
int u, v;
cin >> u >> v;
edges[u].push_back(v);
edges[v].push_back(u);
deg[u] += 1;
deg[v] += 1;
if (start == -1) {
start = u;
}
}
// Check degree
int odd = 0;
REP(i, 0, n) {
odd += deg[i] % 2;
}
if (odd >= 4) {
fail();
}
dfs(start);
REP(i, 0, n) {
if (deg[i] > 0 && not vis[i]) {
fail();
}
}
cout << "YES\n";
}