結果

問題 No.483 マッチ並べ
ユーザー pekempeypekempey
提出日時 2017-02-10 22:52:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 70,164 KB
実行使用メモリ 4,896 KB
最終ジャッジ日時 2023-08-28 10:34:46
合計ジャッジ時間 2,444 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,692 KB
testcase_01 AC 3 ms
4,700 KB
testcase_02 AC 3 ms
4,580 KB
testcase_03 AC 3 ms
4,736 KB
testcase_04 AC 3 ms
4,744 KB
testcase_05 AC 3 ms
4,628 KB
testcase_06 AC 3 ms
4,576 KB
testcase_07 AC 3 ms
4,744 KB
testcase_08 AC 3 ms
4,568 KB
testcase_09 AC 3 ms
4,720 KB
testcase_10 AC 3 ms
4,684 KB
testcase_11 AC 3 ms
4,760 KB
testcase_12 AC 2 ms
4,632 KB
testcase_13 AC 3 ms
4,740 KB
testcase_14 AC 3 ms
4,604 KB
testcase_15 AC 3 ms
4,684 KB
testcase_16 AC 3 ms
4,680 KB
testcase_17 AC 2 ms
4,628 KB
testcase_18 AC 3 ms
4,736 KB
testcase_19 AC 3 ms
4,628 KB
testcase_20 AC 3 ms
4,572 KB
testcase_21 AC 3 ms
4,564 KB
testcase_22 AC 2 ms
4,680 KB
testcase_23 AC 3 ms
4,700 KB
testcase_24 AC 3 ms
4,624 KB
testcase_25 AC 3 ms
4,692 KB
testcase_26 AC 3 ms
4,660 KB
testcase_27 AC 3 ms
4,732 KB
testcase_28 AC 3 ms
4,720 KB
testcase_29 AC 3 ms
4,608 KB
testcase_30 AC 3 ms
4,572 KB
testcase_31 AC 3 ms
4,896 KB
testcase_32 AC 2 ms
4,628 KB
testcase_33 AC 3 ms
4,608 KB
testcase_34 AC 2 ms
4,572 KB
testcase_35 AC 3 ms
4,632 KB
testcase_36 AC 3 ms
4,688 KB
testcase_37 AC 3 ms
4,888 KB
testcase_38 AC 3 ms
4,692 KB
testcase_39 AC 3 ms
4,580 KB
testcase_40 AC 3 ms
4,632 KB
testcase_41 AC 3 ms
4,564 KB
testcase_42 AC 3 ms
4,632 KB
testcase_43 AC 3 ms
4,768 KB
testcase_44 AC 3 ms
4,684 KB
testcase_45 AC 3 ms
4,724 KB
testcase_46 AC 3 ms
4,696 KB
testcase_47 AC 3 ms
4,728 KB
testcase_48 AC 2 ms
4,568 KB
testcase_49 AC 3 ms
4,684 KB
testcase_50 AC 3 ms
4,584 KB
testcase_51 AC 3 ms
4,656 KB
testcase_52 AC 3 ms
4,736 KB
testcase_53 AC 3 ms
4,740 KB
testcase_54 AC 3 ms
4,560 KB
testcase_55 AC 2 ms
4,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int par[202020];

int find(int x) {
	if (par[x] == x) return x;
	return par[x] = find(par[x]);
}

bool unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return false;
	par[x] = y;
	return true;
}

int main() {
	iota(par, par + 202020, 0);
	int n;
	cin >> n;
	vector<int> cycle(202020);
	for (int i = 0; i < n; i++) {
		int y1, x1, y2, x2;
		cin >> y1 >> x1 >> y2 >> x2;
		int u = y1 * 200 + x1;
		int v = y2 * 200 + x2;
		if (!unite(u, v)) {
			cycle[u]++;
		}
	}
	for (int i = 0; i < 202020; i++) {
		if (find(i) != i) {
			cycle[find(i)] += cycle[i];
		}
	}
	for (int i = 0; i < 202020; i++) {
		if (cycle[i] >= 2) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}
0