QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#486298 | #1359. Setting Maps | Yansuan_HCl | RE | 1ms | 3940kb | C++14 | 3.7kb | 2024-07-21 18:36:10 | 2024-07-21 18:36:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define U(i,l,r) for (int i(l),END##i(r); i<=END##i; ++i)
#define D(i,l,r) for (int i(l),END##i(r); i>=END##i; --i)
#define ms(x, v) memset(x, v, sizeof(x))
#define il __attribute__((always_inline))
#define vc vector
#define ar array
#define pb push_back
#define eb emplace_back
#define el '\n'
using ll = long long;
#define int ll
const int INF = 0x3f3f3f3f3f3f3f3f;
namespace dinic {
const int N = 2405, M = N * 8;
struct edge { int v, f, pre; } e[M]; int tail[N], ptr = 1;
void single(int u, int v, int f) {
if (ptr + 1 == M) exit(0);
e[++ptr] = {v, f, tail[u]};
tail[u] = ptr;
}
void add(int u, int v, int f) {
single(u, v, f);
single(v, u, 0);
// clog << u << ' ' << v << ' ' << (f == INF ? 999 : f) << endl;
}
int layer[N], que[N];
bool bfs(int s, int t) {
ms(layer, 0); int l = 0, r = 1; que[0] = s; layer[s] = 1;
while (l < r) {
int u = que[l++];
for (int p = tail[u]; p; p = e[p].pre) {
auto [v, f, _] = e[p];
if (!layer[v] && f)
layer[que[r++] = v] = layer[u] + 1;
}
}
return layer[t];
}
int dfs(int u, int in, int t) {
if (u == t || !in) return in;
int out = 0;
for (int &p = tail[u]; p; p = e[p].pre) {
auto &[v, f, _] = e[p];
if (!f || layer[v] != layer[u] + 1) continue;
int c = dfs(v, min(f, in), t);
f -= c; e[p ^ 1].f += c;
in -= c; out += c;
if (!in) break;
}
return out;
}
int flow(int s, int t) {
int orig[N], res = 0;
while (bfs(s, t)) {
memcpy(orig, tail, sizeof(tail));
int cur = dfs(s, INF, t);
res += cur;
// clog << cur << endl;
memcpy(tail, orig, sizeof(tail));
}
return res;
}
}
#define de dinic::
const int N = 205;
int n, m, k, a, b, c[N]; vc<int> g[N], rg[N];
void bfs(int s, bool *vis, const auto &f) {
queue<int> q; q.push(s); vis[s] = 1;
while (q.size()) {
int u = q.front(); q.pop();
for (int v : f[u]) if (!vis[v]) {
vis[v] = 1;
q.push(v);
}
}
}
bool via[N], vib[N];
signed main() {
// freopen("ava.in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin >> n >> m >> k >> a >> b;
U (i, 1, n) cin >> c[i];
pair<int, int> eg[505] {};
U (i, 1, m) {
auto &[u, v] = eg[i]; cin >> u >> v;
g[u].pb(v); rg[v].pb(u);
}
bfs(a, via, g);
bfs(b, vib, rg);
if (!vib[a]) { cout << -1 << el; exit(0); }
int s = de N - 1, t = de N - 2;
#define ot n+
#define val(x) (via[x] && vib[x])
int pt[N][6] {};
U (i, 1, n * 2) U (j, 0, k) pt[i][j] = n * 2 * j + i;
U (i, 1, n * 2) if (val((i - 1) % n + 1)) {
de add(s, pt[i][0], INF);
U (j, 0, k) {
int f = (j ? pt[i][j - 1] : s);
de add(pt[i][j], f, INF);
}
de add(t, pt[i][k], INF);
}
U (j, 1, k)
de add(pt[a][j], (j == k ? t : pt[a][j + 1]), INF);
U (j, 1, k)
de add(pt[ot b][j - 1], pt[ot b][j], INF);
int mark[de N] {};
U (i, 1, n) if (val(i)) {
U (j, 0, k) {
de add(pt[i][j], pt[ot i][j], INF);
de add(pt[ot i][j], pt[i][j], c[i]);
mark[de ptr - 1] = mark[de ptr] = i;
}
U (j, 1, k)
de add(pt[ot i][j], pt[i][j - 1], INF);
}
U (i, 1, m) {
auto [u, v] = eg[i];
if (!val(u) || !val(v)) continue;
U (j, 0, k) {
de add(pt[v][j], pt[ot u][j], INF);
}
}
int f = de flow(s, t);
clog << "#" << f << endl;
if (f > 2e9) { cout << -1 << el; exit(0); }
vc<int> ans;
U (i, 1, de N - 1) for (int p = de tail[i]; p; p = de e[p].pre) if (mark[p]) {
int v = de e[p].v;
if (de layer[i] && !de layer[v]) {
ans.pb(mark[p]);
}
}
cout << ans.size() << el;
for (int u : ans) cout << u << ' ';
cout << el;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3728kb
input:
3 2 5 1 3 1 60 35 1 2 2 3
output:
-1
result:
ok answer = IMPOSSIBLE
Test #2:
score: 0
Accepted
time: 0ms
memory: 3744kb
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:
3 4 5 6
result:
ok answer = 39
Test #3:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
11 17 2 1 11 1000 10 10 10 10 10 10 10 10 10 1000 1 2 1 3 1 4 1 5 1 6 2 7 3 7 4 7 5 8 6 8 7 8 7 9 7 10 8 9 8 11 9 11 10 11
output:
6 5 6 7 8 9 10
result:
ok answer = 60
Test #4:
score: 0
Accepted
time: 0ms
memory: 3940kb
input:
2 2 2 2 1 100 200 1 2 2 1
output:
2 2 1
result:
ok answer = 300
Test #5:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
5 5 5 1 5 1 1 1 1 1 1 2 2 3 3 4 4 5 1 5
output:
-1
result:
ok answer = IMPOSSIBLE
Test #6:
score: -100
Runtime Error
input:
100 120 5 1 5 5367720 2854323 1799056 9744604 3215334 7580413 6269402 3208439 8812449 3297484 2047196 4044341 7514502 2928715 9335004 3935096 6660663 3356480 4801491 5786147 895995 6710240 222342 4469390 1543213 6678041 8838445 6741919 8138951 5273670 8983795 5131484 4245746 7460466 8357966 8464419 ...