結果
| 問題 |
No.483 マッチ並べ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-10 22:52:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 782 bytes |
| コンパイル時間 | 857 ms |
| コンパイル使用メモリ | 71,156 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-29 08:11:44 |
| 合計ジャッジ時間 | 2,371 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 53 |
ソースコード
#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;
}