結果

問題 No.583 鉄道同好会
ユーザー hiroakiehiroakie
提出日時 2017-12-22 23:27:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 827 bytes
コンパイル時間 571 ms
コンパイル使用メモリ 69,344 KB
実行使用メモリ 4,556 KB
最終ジャッジ日時 2023-08-22 21:32:19
合計ジャッジ時間 1,676 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 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 14 ms
4,376 KB
testcase_12 AC 18 ms
4,376 KB
testcase_13 AC 18 ms
4,380 KB
testcase_14 AC 18 ms
4,376 KB
testcase_15 AC 23 ms
4,376 KB
testcase_16 AC 41 ms
4,552 KB
testcase_17 AC 49 ms
4,556 KB
testcase_18 AC 50 ms
4,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
int ct[500],n,m,st;
bool vis[500];
vector<int> G[500];
int main() {
	cin >> n >> m;
	memset(vis, true, sizeof(vis));
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b; 
		vis[a] = false; vis[b]=false;
		st = a;
		G[a].push_back(b); G[b].push_back(a);
		ct[a]++; ct[b]++;
	}
	int oct = 0;
	for (int i = 0; i < n; i++) { if (ct[i] % 2 == 1)oct++; }
	queue<int> q; q.push(st); vis[st] = true;
	while (!q.empty()) {
		int ci = q.front(); q.pop();
		for (int i = 0; i < G[ci].size(); i++) { if (vis[G[ci][i]])continue; vis[G[ci][i]] = true; q.push(G[ci][i]); }
	}
	for (int i = 0; i < n; i++) { if (!vis[i])oct = 100; }
	if (oct == 0 || oct == 2)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}
0