QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282071 | #1359. Setting Maps | zhicheng | WA | 1ms | 3724kb | C++14 | 2.0kb | 2023-12-11 12:28:45 | 2023-12-11 12:28:46 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=210,M=510;
int tot=1,minu,maxu,vis[N<<1],cur[N<<1],lev[N<<1],src,des,first[N<<1],nnext[(M+N)<<1],to[(M+N)<<1];
ll w[(M+N)<<1],ww[(M+N)<<1];
queue<int>q;
vector<int>anss;
void add(int x,int y,ll z){
nnext[++tot]=first[x];
first[x]=tot;
to[tot]=y;
w[tot]=z;
}
bool bfs(){
int u;
while(!q.empty()){
q.pop();
}
for(int i=minu;i<=maxu;i++){
cur[i]=first[i];
lev[i]=-1;
}
lev[src]=0;
q.push(src);
while(!q.empty()){
u=q.front();
q.pop();
for(int e=first[u];e;e=nnext[e]){
if(w[e]&&lev[to[e]]==-1){
lev[to[e]]=lev[u]+1;
q.push(to[e]);
if(to[e]==des){
return 1;
}
}
}
}
return 0;
}
ll dinic(int u,ll flow){
ll res=0,delta;
if(u==des){
return flow;
}
for(int &e=cur[u];e;e=nnext[e]){
if(w[e]&&lev[to[e]]>lev[u]){
delta=dinic(to[e],min(flow-res,w[e]));
if(delta){
w[e]-=delta;
w[e^1]+=delta;
res+=delta;
if(flow==res){
break;
}
}
}
}
if(flow!=res){
lev[u]=-1;
}
return res;
}
void dfs(int u){
vis[u]=1;
for(int e=first[u];e;e=nnext[e]){
if(!vis[to[e]]&&w[e]>0){
dfs(to[e]);
}
}
}
int main(){
int n,m,k,a,b;
ll ans=0;
scanf("%d%d%d%d%d",&n,&m,&k,&src,&des);
des+=n;
minu=1;
maxu=n*2;
for(int i=1;i<=n;i++){
scanf("%d",&a);
add(i,i+n,a);
add(i+n,i,a);
}
while(m--){
scanf("%d%d",&a,&b);
add(a+n,b,1e18);
add(b,a+n,0);
}
memcpy(ww,w,sizeof(w));
while(k--){
while(bfs()){
ans+=dinic(src,1e18);
}
if(ans>=1e18){
printf("-1");
return 0;
}
memset(vis,0,sizeof(vis));
dfs(src);
memcpy(w,ww,sizeof(w));
for(int i=1;i<=n;i++){
if(!vis[i]){
continue;
}
for(int e=first[i];e;e=nnext[e]){
if(vis[i]&&!vis[to[e]]&&to[e]==i+n){
w[e]=ww[e]=1e18;
anss.push_back(i);
}
}
}
}
printf("%d\n",anss.size());
for(auto i:anss){
printf("%d ",i);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3700kb
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: 3724kb
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: 3648kb
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 7 8 2 3 4 5 6
result:
wrong answer User answer is not optimal; judge: 60, user: 70