QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282129 | #1359. Setting Maps | K8He | WA | 0ms | 4092kb | C++14 | 3.0kb | 2023-12-11 14:13:27 | 2023-12-11 14:13:28 |
Judging History
answer
#include <bits/stdc++.h>
#define _for(i, a, b) for (int i = a; i <= b; ++i)
#define for_(i, a, b) for (int i = a; i >= b; --i)
#define far(i, vec) for (auto i : vec)
#define bdmd int mid = (l + r) >> 1
typedef long double ldb;
typedef long long ll;
typedef double db;
typedef std::pair <int, int> pii;
typedef std::pair <ll, ll> pll;
namespace IO {
int rnt () {
int x = 0, w = 1; char c = getchar ();
while (!isdigit (c)) { if (c == '-') w = -1; c = getchar (); }
while (isdigit (c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar ();
return x * w;
}
} // namespace IO
const int N = 210, inf = 1 << 30;
namespace GRAPH {
class Edge {
public:
int v, w, r;
Edge () = default;
Edge (int _v, int _w, int _r) : v (_v), w (_w), r (_r) {}
};
const int V = 2e3 + 10;
class Graph {
private:
std::vector <Edge> tu[V];
public:
void AddEdge (int u, int v, int w) {
int p1 = tu[u].size (), p2 = tu[v].size ();
tu[u].emplace_back (v, w, p2);
tu[v].emplace_back (u, 0, p1);
return;
}
private:
int dep[V], cur[V];
bool BFS (int S, int T) {
memset (dep, 0, sizeof (dep));
std::queue <int> q;
dep[S] = 1, cur[S] = 0, q.push (S);
while (!q.empty ()) {
int u = q.front (); q.pop ();
far (p, tu[u]) {
if (!p.w || dep[p.v]) continue;
dep[p.v] = dep[u] + 1, cur[p.v] = 0;
if (p.v == T) return true;
q.push (p.v);
}
}
return false;
}
int DFS (int u, int T, int flow) {
if (u == T || flow <= 0) return flow;
int sz = tu[u].size () - 1, sum = 0;
for (int& i = cur[u]; i <= sz; ++i) {
auto& p = tu[u][i];
if (!p.w || dep[p.v] != dep[u] + 1) continue;
int k = DFS (p.v, T, std::min (flow, p.w));
p.w -= k, tu[p.v][p.r].w += k;
sum += k, flow -= k;
if (flow <= 0) break;
}
return sum;
}
public:
int Dinic (int S, int T) {
int maxflow = 0;
while (BFS (S, T)) {
int f = DFS (S, T, inf);
if (f == inf) return inf;
maxflow += f;
}
return maxflow;
}
};
} // namespace GRAPH
namespace SOLVE {
using namespace IO;
int n, m, K, S, T, c[N], ans;
GRAPH::Graph G;
int ID (int u, int op, int k) {
return u * 2 - op + (k - 1) * n * 2;
}
void In () {
n = rnt (), m = rnt (), K = rnt (), S = rnt (), T = rnt ();
_for (i, 1, n) c[i] = rnt ();
_for (i, 1, m) {
int u = rnt (), v = rnt ();
_for (k, 1, K)
G.AddEdge (ID (u, 1, k), ID (v, 0, k), inf);
}
return;
}
void Solve () {
_for (i, 1, n) {
G.AddEdge (ID (i, 0, 1), ID (i, 1, 1), c[i]);
_for (k, 2, K) {
G.AddEdge (ID (i, 0, k), ID (i, 1, k), c[i]);
G.AddEdge (ID (i, 0, k - 1), ID (i, 1, k), inf);
}
}
_for (k, 2, K)
G.AddEdge (ID (T, 1, k - 1), ID (T, 1, k), inf);
ans = G.Dinic (ID (S, 0, 1), ID (T, 1, K));
return;
}
void Out () {
printf ("%d\n", ans >= inf ? -1 : ans);
return;
}
}
int main () {
SOLVE::In ();
SOLVE::Solve ();
SOLVE::Out ();
return 0;
} /*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
input:
3 2 5 1 3 1 60 35 1 2 2 3
output:
-1
result:
ok answer = IMPOSSIBLE
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 4092kb
input:
7 11 1 1 7 100 5 7 16 11 12 100 1 2 1 3 1 4 1 5 2 3 2 6 3 6 4 3 4 7 5 7 6 7
output:
39
result:
wrong answer Integer parameter [name=p; number of vertices] equals to 39, violates the range [-1, 7]