結果
| 問題 |
No.483 マッチ並べ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-16 17:14:57 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 2,258 bytes |
| コンパイル時間 | 854 ms |
| コンパイル使用メモリ | 73,448 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-30 00:19:28 |
| 合計ジャッジ時間 | 2,635 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 53 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:84:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
84 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:89:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
89 | int r0, c0, r1, c1; scanf("%d%d%d%d", &r0, &c0, &r1, &c1);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
constexpr int inf = 987654321;
struct Edge {
int dst, rev;
int capa;
};
class Graph {
protected:
int size;
vector<vector<Edge>> g;
public:
Graph(int size) : size(size) { g.resize(size); }
void add_edge(int src, int dst, int capa);
int max_flow(int s, int t) { throw; }
};
class Dinic : public Graph {
vector<int> level, iter;
void bfs(int s);
int dfs(int v, int t, int flow);
public:
Dinic(int size) : Graph(size) {}
int max_flow(int s, int t);
};
void Graph::add_edge(int src, int dst, int capa) {
g[src].push_back(Edge({dst, int(g[dst].size()), capa}));
g[dst].push_back(Edge({src, int(g[src].size())-1, 0}));
}
void Dinic::bfs(int s) {
level.assign(size, -1);
queue<int> que;
level[s] = 0;
que.push(s);
while(!que.empty()) {
int v = que.front(); que.pop();
for(Edge& e : g[v]) {
if(e.capa > 0 && level[e.dst] < 0) {
level[e.dst] = level[v] + 1;
que.push(e.dst);
}
}
}
}
int Dinic::dfs(int v, int t, int flow) {
if(v == t) { return flow; }
for(int& i=iter[v], n=g[v].size(); i<n; ++i) {
Edge& e = g[v][i];
if(e.capa <= 0 || level[v] >= level[e.dst]) { continue; }
int d = dfs(e.dst, t, min(flow, e.capa));
if(d > 0) {
e.capa -= d;
g[e.dst][e.rev].capa += d;
return d;
}
}
return 0;
}
int Dinic::max_flow(int s, int t) {
int res = 0;
while(true) {
bfs(s);
if(level[t] < 0) { return res; }
iter.assign(size, 0);
int flow;
while((flow = dfs(s, t, inf)) > 0) {
res += flow;
if(res >= inf) { return inf; }
}
}
}
int main(void) {
constexpr int N = 111;
int n; scanf("%d", &n);
Dinic graph(n + N*N + 2);
int s = n + N*N,
t = s + 1;
for(int i=0; i<n; ++i) {
int r0, c0, r1, c1; scanf("%d%d%d%d", &r0, &c0, &r1, &c1);
int x = n + r0 * N + c0,
y = n + r1 * N + c1;
graph.add_edge(s, i, 1);
graph.add_edge(i, x, 1);
graph.add_edge(i, y, 1);
}
for(int r=0; r<N; ++r) {
for(int c=0; c<N; ++c) {
int x = n + r * N + c;
graph.add_edge(x, t, 1);
}
}
int max_flow = graph.max_flow(s, t);
puts(max_flow == n ? "YES" : "NO");
return 0;
}