結果
| 問題 |
No.483 マッチ並べ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-10 23:20:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,239 bytes |
| コンパイル時間 | 944 ms |
| コンパイル使用メモリ | 82,964 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-29 11:10:14 |
| 合計ジャッジ時間 | 2,655 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 29 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef struct __match {
int x1;
int y1;
int x2;
int y2;
} Match;
bool touches(Match a, Match b) {
if ((a.x1 == b.x1 && a.y1 == b.y1) ||
(a.x1 == b.x1 && b.y2 == b.y2) ||
(a.x2 == b.x2 && a.y1 == b.y1) ||
(a.x2 == b.x2 && a.y2 == b.y2)
)
{
return true;
} else {
return false;
}
}
int main() {
int n, a, b, c, d;
cin >> n;
vector<Match> matches(n);
for (int i = 0; i < n; i++) {
cin >> a >> b >> c >> d;
Match m = {a, b, c, d};
matches[i] = m;
}
vector<set<int>> connect(n);
for (int i = 0; i < n; i++) {
Match m1 = matches[i];
for (int j = i + 1; j < n; j++) {
Match m2 = matches[j];
if (touches(m1, m2)) {
connect[i].insert(j);
connect[j].insert(i);
}
}
}
bool updates = true;
do {
updates = false;
for (int i = 0; i < n; i++) {
if (connect[i].size() == 1) {
int tmp = *(connect[i].begin());
connect[i].erase(tmp);
connect[tmp].erase(i);
updates = true;
}
}
} while (updates);
int maxi = 0;
for (int i = 0; i < n; i++) {
maxi = max(maxi, (int)connect[i].size());
}
cout << (maxi > 1 ? "NO" : "YES") << endl;
return 0;
}