QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#282133 | #1359. Setting Maps | GeZhiyuan | WA | 1ms | 6016kb | C++14 | 2.3kb | 2023-12-11 14:19:11 | 2023-12-11 14:19:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll V = 2000 + 5, E = 1e6 + 5, Inf = 0x3f3f3f3f3f3f3f3f;
ll tot = 0, ver[E] = {}, cap[E] = {}, dis[V] = {}, cur[V] = {}, col[V] = {};
vector<ll> G[V] = {};
queue<ll> Q;
inline bool bfs(ll s, ll t){
memset(dis, 0x3f, sizeof(dis)), memset(cur, 0, sizeof(cur));
dis[s] = 0;
Q.push(s);
while(Q.size()){
ll u = Q.front(); Q.pop();
for(ll i = 0 ; i < (ll)G[u].size() ; i ++){
ll e = G[u][i], v = ver[e];
if(dis[v] == Inf && cap[e]){
dis[v] = dis[u] + 1;
Q.push(v);
}
}
}
return dis[t] != Inf;
}
inline ll dfs(ll u, ll t, ll f){
if(u == t || !f) return f;
ll ret = 0;
for(ll &i = cur[u] ; i < (ll)G[u].size() ; i ++){
ll e = G[u][i], v = ver[e];
if(cap[e] && dis[v] == dis[u] + 1){
ll x = dfs(v, t, min(cap[e], f - ret));
if(x) ret += x, cap[e] -= x, cap[e ^ 1] += x;
}
if(ret == f) return ret;
}
return ret;
}
inline void addedge(ll u, ll v, ll w){
G[u].push_back(tot), ver[tot] = v, cap[tot] = w, tot ++;
G[v].push_back(tot), ver[tot] = u, cap[tot] = 0, tot ++;
}
inline void paint(ll u){
col[u] = 1;
for(ll e : G[u]){
ll v = ver[e], w = cap[e];
if(w && !col[v]) paint(v);
}
}
inline ll dinic(ll s, ll t){
ll ret = 0;
while(bfs(s, t)){
ret += dfs(s, t, Inf);
if(ret >= Inf){
printf("-1");
exit(0);
}
}
paint(s);
return ret;
}
ll n = 0, m = 0, k = 0, s = 0, t = 0;
vector<ll> ans;
int main(){
scanf("%lld %lld %lld", &n, &m, &k); k --;
scanf("%lld %lld", &s, &t); s --, t --;
for(ll i = 0, c = 0 ; i < n ; i ++){
scanf("%lld", &c);
for(ll x = 0 ; x <= k ; x ++) addedge((2 * x) * n + i, (2 * x + 1) * n + i, c);
for(ll x = 0 ; x < k ; x ++) addedge((2 * x) * n + i, (2 * x + 3) * n + i, Inf);
}
for(ll x = 0 ; x < k ; x ++) addedge((2 * x + 1) * n + t, (2 * x + 3) * n + t, Inf);
for(ll i = 0, u = 0, v = 0 ; i < m ; i ++){
scanf("%lld %lld", &u, &v); u --, v --;
for(ll x = 0 ; x <= k ; x ++) addedge((2 * x + 1) * n + u, (2 * x) * n + v, Inf);
}
dinic(s, (2 * k + 1) * n + t);
for(ll i = 0 ; i < n ; i ++) for(ll x = 0 ; x <= k ; x ++) if(col[(2 * x) * n + i] != col[(2 * x + 1) * n + i]){
ans.push_back(i);
break;
}
printf("%lld\n", (ll)ans.size());
for(ll x : ans) printf("%lld ", x + 1);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5912kb
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: 1ms
memory: 6016kb
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:
4 2 3 4 5
result:
ok answer = 39
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5892kb
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:
7 1 5 6 7 8 9 10
result:
wrong answer User answer is not optimal; judge: 60, user: 1060