結果

問題 No.583 鉄道同好会
ユーザー square1001square1001
提出日時 2018-01-21 16:54:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 775 bytes
コンパイル時間 1,007 ms
コンパイル使用メモリ 88,164 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 19:42:47
合計ジャッジ時間 1,985 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 13 ms
4,380 KB
testcase_12 AC 17 ms
4,376 KB
testcase_13 AC 16 ms
4,376 KB
testcase_14 AC 17 ms
4,376 KB
testcase_15 AC 21 ms
4,380 KB
testcase_16 AC 38 ms
4,376 KB
testcase_17 AC 46 ms
4,376 KB
testcase_18 AC 46 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0