結果

問題 No.483 マッチ並べ
ユーザー tansunogontansunogon
提出日時 2017-05-05 15:49:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,354 bytes
コンパイル時間 1,215 ms
コンパイル使用メモリ 87,492 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 09:47:48
合計ジャッジ時間 3,155 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,352 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,352 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 1 ms
4,352 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,352 KB
testcase_47 AC 1 ms
4,352 KB
testcase_48 AC 1 ms
4,352 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 1 ms
4,348 KB
testcase_51 AC 2 ms
4,352 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 2 ms
4,352 KB
testcase_54 AC 1 ms
4,348 KB
testcase_55 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

struct iostream_init_struct
{ 
	iostream_init_struct()
	{
		std::cin.tie(0);
		std::cin.sync_with_stdio(false);
	}
} iostream_init;

#include <unordered_map>
template <class TYPE, class TYPE_HASH>
class union_find
{
private:
	std::unordered_map<TYPE, TYPE, TYPE_HASH> parent_;
	std::unordered_map<TYPE, int, TYPE_HASH> loop_;
public:
	TYPE find(TYPE x)
	{
		auto itr = parent_.find(x);
		if (itr == parent_.end())
			return x;
		else
		{
			TYPE parent = itr->second;
			return parent_[x] = find(parent);
		}
	}
	// returns num of loop
	int unite(TYPE x, TYPE y)
	{
		TYPE x_parent = find(x);
		TYPE y_parent = find(y);
		if (x_parent == y_parent)
		{
			return loop_[x_parent] += 1;
		}
		parent_[y_parent] = x_parent;

		int ret = loop_[x_parent] += loop_[y_parent];
		loop_.erase(y_parent);
		return ret;
	}
	bool is_same(TYPE x, TYPE y)
	{
		return find(x) == find(y);
	}
};

class PairHash
{
public:
	size_t operator()(const pair<int, int>& obj) const
	{
		return obj.first * 1000 + obj.second;
	}
};

int main(void)
{
	union_find<pair<int, int>, PairHash> m;
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		int r0, c0, r1, c1;
		cin >> r0 >> c0 >> r1 >> c1;
		if (m.unite(make_pair(r0, c0), make_pair(r1, c1)) >= 2)
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}
0