結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,564 KB
testcase_01 AC 4 ms
6,556 KB
testcase_02 AC 4 ms
6,632 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 4 ms
6,708 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 5 ms
6,572 KB
testcase_12 AC 4 ms
6,488 KB
testcase_13 AC 5 ms
6,632 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 4 ms
6,560 KB
testcase_17 AC 4 ms
6,612 KB
testcase_18 AC 4 ms
6,508 KB
testcase_19 WA -
testcase_20 AC 4 ms
6,500 KB
testcase_21 AC 4 ms
6,512 KB
testcase_22 AC 4 ms
6,828 KB
testcase_23 AC 4 ms
6,500 KB
testcase_24 AC 4 ms
6,700 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 4 ms
6,560 KB
testcase_28 AC 5 ms
6,576 KB
testcase_29 AC 4 ms
6,524 KB
testcase_30 WA -
testcase_31 AC 4 ms
6,836 KB
testcase_32 AC 5 ms
6,500 KB
testcase_33 AC 5 ms
6,492 KB
testcase_34 AC 4 ms
6,552 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 4 ms
6,820 KB
testcase_41 AC 4 ms
6,560 KB
testcase_42 AC 4 ms
6,560 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 4 ms
6,512 KB
testcase_54 AC 5 ms
6,708 KB
testcase_55 AC 4 ms
6,624 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) {
            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;
}
0