結果
| 問題 |
No.483 マッチ並べ
|
| コンテスト | |
| ユーザー |
ふーらくたる
|
| 提出日時 | 2017-02-11 00:09:58 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,389 bytes |
| コンパイル時間 | 879 ms |
| コンパイル使用メモリ | 74,032 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-29 11:25:46 |
| 合計ジャッジ時間 | 2,545 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 28 |
ソースコード
#include <iostream>
#include <map>
#include <cstring>
#include <vector>
using namespace std;
using P = pair<int, int>;
int dr[4] = {1, 0, -1, 0},
dc[4] = {0, 1, 0, -1};
const int NUM = 114514;
vector<int> graph[NUM];
int color[NUM];
bool dfs(int v, int c, int prev) {
color[v] = c;
for (int to : graph[v]) {
if (to == prev) continue;
if (color[to] < 0) {
return dfs(to, 1, v);
} else if (color[to] == c) {
return false;
}
}
return true;
}
int main() {
int n;
cin >> n;
memset(color, -1, sizeof(color));
int id = 0;
map<P, int> dict;
for (int i = 0; i < n; i++) {
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
P p1 = make_pair(r1, c1),
p2 = make_pair(r2, c2);
int id1, id2;
if (dict.find(p1) == dict.end()) {
dict[p1] = id;
id++;
}
if (dict.find(p2) == dict.end()) {
dict[p2] = id;
id++;
}
id1 = dict[p1];
id2 = dict[p2];
graph[id1].push_back(id2);
graph[id2].push_back(id1);
}
for (int v = 0; v < id; v++) {
if (color[v] == -1) {
if (!dfs(v, 0, -1)) {
cout << "NO" << endl;
return 0;
}
}
}
cout << "YES" << endl;
return 0;
}
ふーらくたる