結果

問題 No.483 マッチ並べ
ユーザー tubo28tubo28
提出日時 2017-02-10 22:55:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 2,146 bytes
コンパイル時間 1,636 ms
コンパイル使用メモリ 172,076 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 10:35:03
合計ジャッジ時間 5,240 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
4,380 KB
testcase_01 AC 26 ms
4,380 KB
testcase_02 AC 25 ms
4,376 KB
testcase_03 AC 26 ms
4,376 KB
testcase_04 AC 28 ms
4,376 KB
testcase_05 AC 26 ms
4,380 KB
testcase_06 AC 26 ms
4,380 KB
testcase_07 AC 26 ms
4,376 KB
testcase_08 AC 25 ms
4,376 KB
testcase_09 AC 27 ms
4,380 KB
testcase_10 AC 28 ms
4,376 KB
testcase_11 AC 26 ms
4,380 KB
testcase_12 AC 27 ms
4,376 KB
testcase_13 AC 27 ms
4,376 KB
testcase_14 AC 24 ms
4,376 KB
testcase_15 AC 25 ms
4,376 KB
testcase_16 AC 27 ms
4,376 KB
testcase_17 AC 28 ms
4,376 KB
testcase_18 AC 26 ms
4,376 KB
testcase_19 AC 26 ms
4,376 KB
testcase_20 AC 27 ms
4,376 KB
testcase_21 AC 24 ms
4,376 KB
testcase_22 AC 25 ms
4,376 KB
testcase_23 AC 28 ms
4,376 KB
testcase_24 AC 27 ms
4,380 KB
testcase_25 AC 26 ms
4,380 KB
testcase_26 AC 27 ms
4,380 KB
testcase_27 AC 28 ms
4,380 KB
testcase_28 AC 28 ms
4,380 KB
testcase_29 AC 29 ms
4,376 KB
testcase_30 AC 24 ms
4,380 KB
testcase_31 AC 29 ms
4,376 KB
testcase_32 AC 25 ms
4,380 KB
testcase_33 AC 23 ms
4,380 KB
testcase_34 AC 28 ms
4,376 KB
testcase_35 AC 25 ms
4,380 KB
testcase_36 AC 26 ms
4,380 KB
testcase_37 AC 27 ms
4,380 KB
testcase_38 AC 28 ms
4,376 KB
testcase_39 AC 29 ms
4,376 KB
testcase_40 AC 27 ms
4,376 KB
testcase_41 AC 25 ms
4,380 KB
testcase_42 AC 28 ms
4,380 KB
testcase_43 AC 28 ms
4,376 KB
testcase_44 AC 26 ms
4,380 KB
testcase_45 AC 26 ms
4,380 KB
testcase_46 AC 27 ms
4,376 KB
testcase_47 AC 28 ms
4,380 KB
testcase_48 AC 25 ms
4,376 KB
testcase_49 AC 26 ms
4,380 KB
testcase_50 AC 29 ms
4,380 KB
testcase_51 AC 28 ms
4,380 KB
testcase_52 AC 24 ms
4,376 KB
testcase_53 AC 28 ms
4,376 KB
testcase_54 AC 30 ms
4,376 KB
testcase_55 AC 25 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
template<typename T> void __dump__(const T &first){ std::cerr << first << std::endl; }
template<typename First, typename... Rest>
void __dump__(const First& first, const Rest&... rest) { std::cerr << first << ", "; __dump__(rest...); }
#define dump(...) { std::cerr << __LINE__ << ":\t" #__VA_ARGS__ " = "; __dump__(__VA_ARGS__); }

const int R = 120;
const int C = 120;
const int N = R*C;

class bipartite_matching {
public:
    int n;
    vector<vector<int>> g;
    vector<int> match;

    bipartite_matching(int n_) : n(n_), g(n_), match(n_), used(n_) {}

    void add_edge(int u, int v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int maximum_matching(void) {
        int res = 0;
        fill(begin(match), end(match), -1);
        for (int v = 0; v < n; ++v) {
            if (match[v] == -1) {
                fill(begin(used), end(used), false);
                if (dfs(v)) res++;
            }
        }
        return res;
    }

private:
    vector<int> used;
    bool dfs(int v) {
        used[v] = true;
        for (int u : g[v]) {
            int w = match[u];
            if (w == -1 || (!used[w] && dfs(w))) {
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }
};

int enc(int r, int c){
    return r*C + c;
}

int main(){
    int n;
    while(cin >> n){
        bipartite_matching bm(N + 100);
        rep(i, n){
            int r, c, rr, cc;
            cin >> r >> c >> rr >> cc;
            --r, --c, --rr, --cc;
            int x = enc(r, c), y = enc(rr, cc);
            bm.add_edge(i, x + 100);
            bm.add_edge(i, y + 100);
        }
        int f = bm.maximum_matching();
        dump(f);
        puts(f == n ? "YES" : "NO");
    }
}
0