結果
問題 | No.583 鉄道同好会 |
ユーザー |
![]() |
提出日時 | 2018-01-21 16:54:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 775 bytes |
コンパイル時間 | 1,046 ms |
コンパイル使用メモリ | 90,188 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-25 21:17:02 |
合計ジャッジ時間 | 2,284 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <cmath>#include <string>#include <vector>#include <iomanip>#include <iostream>#include <algorithm>#include <functional>using namespace std;int n, m, a, b, d[509], par[509];int root(int x) { return x == par[x] ? x : par[x] = root(par[x]); }int main() {cin >> n >> m;for (int i = 0; i < n; i++) par[i] = i;for (int i = 0; i < m; i++) {cin >> a >> b;d[a]++; d[b]++;par[root(a)] = root(b);}vector<int> s;for (int i = 0; i < n; i++) {if (d[i] >= 1) s.push_back(root(i));}sort(s.begin(), s.end());bool ret = true;for (int i = 1; i < s.size(); i++) {if (s[i - 1] != s[i]) ret = false;}int cnt = 0;for (int i = 0; i < n; i++) {if (d[i] % 2 == 1) cnt++;}cout << (cnt >= 3 || !ret ? "NO" : "YES") << endl;return 0;}