結果
問題 |
No.483 マッチ並べ
|
ユーザー |
![]() |
提出日時 | 2017-02-11 02:01:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,957 bytes |
コンパイル時間 | 1,516 ms |
コンパイル使用メモリ | 119,096 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-29 11:51:18 |
合計ジャッジ時間 | 3,137 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 31 WA * 22 |
ソースコード
#include <iostream> #include <string> #include <queue> #include <stack> #include <algorithm> #include <list> #include <vector> #include <complex> #include <utility> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <bitset> #include <ctime> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <cassert> #include <cstddef> #include <iomanip> #include <numeric> #include <tuple> #include <sstream> #include <fstream> using namespace std; #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++) #define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--) #define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--) #define DEBUG(C) cerr << #C << " = " << C << endl; using LL = long long; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<LL>; using VVL = vector<VL>; using VD = vector<double>; using VVD = vector<VD>; using PII = pair<int, int>; using PDD = pair<double, double>; using PLL = pair<LL, LL>; using VPII = vector<PII>; template<typename T> using VT = vector<T>; #define ALL(a) begin((a)), end((a)) #define RALL(a) rbegin((a)), rend((a)) #define SORT(a) sort(ALL((a))) #define RSORT(a) sort(RALL((a))) #define REVERSE(a) reverse(ALL((a))) #define MP make_pair #define FORE(a, b) for (auto &&a : (b)) #define FIND(s, e) ((s).find(e) != (s).end()) #define EB emplace_back template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;} template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;} const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; //超点数や流量がめっちゃ大きいときは Dinic!! //蟻本P190~ class FordFulkerson { struct edge { int to, rev; //行き先,逆辺(のid) long long cap; //容量 edge(int _to, int _rev, long long _cap) { this->to = _to; this->rev = _rev; this->cap = _cap; } }; private: vector<vector<edge>> G; vector<bool> used; long long dfs(int v, int t, long long f) { if (v == t) return f; used[v] = true; for (auto &&el : G[v]) { if (used[el.to] || el.cap <= 0) { continue; } long long d = dfs(el.to, t, min(f, el.cap)); if (d > 0) { el.cap -= d; G[el.to][el.rev].cap += d; return d; } } return 0; } public: FordFulkerson() {} FordFulkerson(int n) { G.resize(n); used.resize(n, false); } void add_edge(int from, int to, long long cap) { G[from].emplace_back(edge(to, G[to].size(), cap)); G[to].emplace_back(edge(from, G[from].size() - 1, 0)); } long long max_flow(int s, int t) { if (s == t) return 0; long long flow = 0; while (1) { fill(begin(used), end(used), false); long long f = dfs(s, t, LLINF); if (f == 0) return flow; flow += f; } } }; const int SIZE = 120; FordFulkerson ff(SIZE * SIZE); int N; PII ip(int n) { return MP(n / SIZE, n % SIZE); } int pi(PII p) { return p.first * SIZE + p.second; } int pi(int r, int c) { return pi(MP(r, c)); } int main(void) { const int s = 0, t = SIZE * SIZE - 1; scanf("%d", &N); REP(i, N) { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); // s -> マッチ棒(棒はidxで表す) ff.add_edge(s, i + 1, 1); // マッチ棒 -> 棒の2つの頂点 ff.add_edge(i + 1, pi(a, b) + SIZE, 1); ff.add_edge(i + 1, pi(c, d) + SIZE, 1); // 2つの頂点 -> t ff.add_edge(pi(a, b) + SIZE, t, 1); ff.add_edge(pi(c, d) + SIZE, t, 1); } cout << (ff.max_flow(s, t) == N ? "YES" : "NO") << endl; }