QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#77979 | #1359. Setting Maps | Illusory_dimes | WA | 2ms | 3556kb | C++17 | 2.9kb | 2023-02-16 11:17:16 | 2023-02-16 11:17:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout);
#define Check(a) freopen(a".in", "r", stdin), freopen(a".ans", "w", stdout);
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef __int128_t i7;
typedef __uint128_t u7;
typedef long double ld;
typedef pair<int, int> pii;
#define mp make_pair
#define fi first
#define se second
#define eps 1e-10
const int mod = 1e9 + 7;
template <typename A>
inline int M(A x) {return x;}
template <typename A, typename ... B>
inline int M(A x, B ... args) {return 1ll * x * M(args ...) % mod;}
inline int mim(const int &x) {return x >= mod ? x - mod : x;}
inline int adm(const int &x) {return x < 0 ? x + mod : x;}
inline void mi(int &x, const int &y) {x += y; x >= mod && (x -= mod);}
inline void ad(int &x, const int &y) {x -= y; x < 0 && (x += mod);}
const int N = 208, K = 8, D = N * K * 2, F = D << 2;
const ll INF = 0x3f3f3f3f3f;
int n, m, k, B, E, sz, s, t, fst[D], tot = 1;
int in[N][K], out[N][K];
struct edge {int nxt, to; ll va;} e[F << 1];
#define add(u, v, w) (e[++tot] = (edge) {fst[u], v, w}, fst[u] = tot)
#define ADD(u, v, w) (add(u, v, w), add(v, u, w))
int cur[D], d[D]; bool vis[D];
inline bool bfs() {
for (int i = 1; i <= sz; ++i) d[i] = vis[i] = 0, cur[i] = fst[i];
queue<int> q; d[s] = 1; q.push(s);
while (!q.empty()) {
int u = q.front(); q.pop(); vis[u] = 1;
for (int i = fst[u], v; i; i = e[i].nxt)
e[i].va && !d[v = e[i].to] && (q.push(v), d[v] = d[u] + 1);
}
return d[t] > 0;
}
inline ll dfs(int u, ll flow) {
if (u == t || !flow) return flow;
ll re = 0, tm;
for (int &i = cur[u], v; i; i = e[i].nxt) {
if (e[i].va && d[v = e[i].to] == d[u] + 1) {
re += (tm = dfs(v, min(flow, e[i].va)));
e[i].va -= tm, flow -= tm, e[i ^ 1].va += tm;
if (!flow) break;
}
}
(!re || flow) && (d[u] = 0); return re;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> k >> B >> E; sz = t = (s = 1) + 1;
for (int i = 1; i <= n; ++i) for (int j = 1; j <= k; ++j) in[i][j] = ++sz, out[i][j] = ++sz;
ADD(s, in[B][1], INF);
for (int j = 1; j <= k; ++j) ADD(out[E][j], t, INF);
for (int i = 1, c; i <= n; ++i) {
cin >> c; ADD(in[i][k], out[i][k], c);
for (int j = 1; j < k; ++j) ADD(in[i][j], out[i][j], c), ADD(in[i][j], out[i][j + 1], INF);
}
for (int i = 1, u, v; i <= m; ++i) {
cin >> u >> v;
for (int j = 1; j <= k; ++j) ADD(out[u][j], in[v][j], INF);
}
ll re = 0; while (bfs()) re += dfs(s, INF);
if (re >= INF) return cout << "-1\n", 0;
vector<int> v;
for (int i = 1; i <= n; ++i) {
bool fg = 0;
for (int j = 1; j <= k; ++j)
if (vis[in[i][j]] > vis[out[i][j]]) {fg = 1; break;}
if (fg) v.push_back(i);
}
cout << v.size() << "\n";
for (int x : v) cout << x << " ";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3556kb
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: 2ms
memory: 3552kb
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:
1 1
result:
wrong answer User answer is not optimal; judge: 39, user: 100