結果

問題 No.483 マッチ並べ
ユーザー ふーらくたるふーらくたる
提出日時 2017-02-11 00:07:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,401 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 74,428 KB
実行使用メモリ 6,832 KB
最終ジャッジ日時 2023-08-28 12:30:15
合計ジャッジ時間 2,778 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,692 KB
testcase_01 AC 4 ms
6,576 KB
testcase_02 AC 4 ms
6,492 KB
testcase_03 AC 4 ms
6,608 KB
testcase_04 AC 4 ms
6,548 KB
testcase_05 AC 5 ms
6,556 KB
testcase_06 AC 5 ms
6,472 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 4 ms
6,640 KB
testcase_12 AC 4 ms
6,648 KB
testcase_13 AC 4 ms
6,572 KB
testcase_14 AC 4 ms
6,508 KB
testcase_15 WA -
testcase_16 AC 4 ms
6,500 KB
testcase_17 AC 4 ms
6,560 KB
testcase_18 AC 4 ms
6,496 KB
testcase_19 WA -
testcase_20 AC 4 ms
6,548 KB
testcase_21 AC 4 ms
6,552 KB
testcase_22 AC 5 ms
6,624 KB
testcase_23 AC 5 ms
6,504 KB
testcase_24 AC 4 ms
6,628 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 4 ms
6,556 KB
testcase_28 AC 4 ms
6,572 KB
testcase_29 AC 4 ms
6,624 KB
testcase_30 AC 5 ms
6,508 KB
testcase_31 AC 4 ms
6,548 KB
testcase_32 AC 4 ms
6,516 KB
testcase_33 AC 4 ms
6,472 KB
testcase_34 AC 4 ms
6,640 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 5 ms
6,568 KB
testcase_40 AC 4 ms
6,608 KB
testcase_41 AC 5 ms
6,700 KB
testcase_42 AC 5 ms
6,548 KB
testcase_43 AC 5 ms
6,508 KB
testcase_44 AC 4 ms
6,548 KB
testcase_45 AC 4 ms
6,496 KB
testcase_46 AC 5 ms
6,560 KB
testcase_47 AC 4 ms
6,580 KB
testcase_48 AC 4 ms
6,484 KB
testcase_49 AC 4 ms
6,704 KB
testcase_50 AC 4 ms
6,584 KB
testcase_51 AC 5 ms
6,564 KB
testcase_52 AC 4 ms
6,520 KB
testcase_53 AC 5 ms
6,616 KB
testcase_54 AC 5 ms
6,540 KB
testcase_55 AC 4 ms
6,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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) {
            if (!dfs(to, 1, v)) return false;
        } 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;
}
0