結果

問題 No.583 鉄道同好会
ユーザー ldsybldsyb
提出日時 2017-10-28 00:03:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 962 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 174,668 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 18:09:29
合計ジャッジ時間 2,462 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 WA -
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 14 ms
6,940 KB
testcase_12 AC 19 ms
6,944 KB
testcase_13 AC 18 ms
6,944 KB
testcase_14 AC 18 ms
6,940 KB
testcase_15 AC 23 ms
6,944 KB
testcase_16 AC 42 ms
6,944 KB
testcase_17 AC 51 ms
6,944 KB
testcase_18 AC 51 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <typename T>
struct graph {
	
	struct edge {
		int from, to;
		T cost;
	};
	
	vector<edge> edges;
	vector<vector<int>> g;
	int n;
	
	graph(int n) : n(n) {
		g.resize(n);
	}
	
	virtual void add(int from, int to, T cost) = 0;
};

template <typename T>
struct undirected_graph : graph<T> {
	using graph<T>::edges;
	using graph<T>::g;
	using graph<T>::n;
	
	undirected_graph(int n) : graph<T>(n) {
	}
	
	void add(int from, int to, T cost = 1) {
		assert(0 <= from && from < n && 0 <= to && to < n);
		g[from].emplace_back(edges.size());
		g[to].emplace_back(edges.size());
		edges.push_back({from, to, cost});
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	undirected_graph<int> g(n);
	for (int i = 0; i < m; i++) {
		int from, to;
		cin >> from >> to;
		g.add(from, to);
	}
	int puni = 0;
	for (auto &v : g.g) {
		if (v.size() & 1) {
			puni++;
		}
	}
	cout << (puni < 3 ? "YES" : "NO") << endl;
	return 0;
}
0