QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282095 | #1359. Setting Maps | SoyTony | WA | 0ms | 3832kb | C++14 | 2.6kb | 2023-12-11 13:17:13 | 2023-12-11 13:17:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=205;
const int maxm=505;
const int inf=0x3f3f3f3f;
inline int read(){
int x=0,w=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*w;
}
int n,m,k;
int s,t;
int val[maxn];
vector<int> E[maxn];
int d[maxn];
int S,T;
struct edge{
int to,nxt,w;
}e[maxn*20+maxm*10];
int head[maxn*10],cnt;
inline void add_edge(int u,int v,int w){
e[++cnt].to=v,e[cnt].nxt=head[u],head[u]=cnt,e[cnt].w=w;
e[++cnt].to=u,e[cnt].nxt=head[v],head[v]=cnt,e[cnt].w=0;
}
int cur[maxn*10],dis[maxn*10];
int dfs(int u,int rest){
if(u==T) return rest;
int flow=0;
for(int i=cur[u],v,w;i&&rest;i=e[i].nxt){
cur[u]=i;
v=e[i].to,w=e[i].w;
if(dis[u]+1==dis[v]&&w){
int k=dfs(v,min(rest,w));
flow+=k,rest-=k;
e[i].w-=k,e[i^1].w+=k;
}
}
if(!flow) dis[u]=-1;
return flow;
}
queue<int> q;
inline int MF(){
int flow=0;
while(1){
memcpy(cur,head,sizeof(head));
memset(dis,-1,sizeof(dis));
dis[S]=0;
q.push(S);
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=head[u],v,w;i;i=e[i].nxt){
v=e[i].to,w=e[i].w;
if(dis[v]==-1&&w){
dis[v]=dis[u]+1;
q.push(v);
}
}
}
if(dis[T]==-1) return flow;
flow+=dfs(S,inf);
}
}
int main(){
// freopen("apers.in","r",stdin);
// freopen("apers.out","w",stdout);
n=read(),m=read(),k=read();
s=read(),t=read();
S=2*k*n+1,T=2*k*n+2;
cnt=1;
add_edge(S,s,inf),add_edge((2*k-1)*n+t,T,inf);
for(int i=1;i<=n;++i){
val[i]=read();
for(int j=1;j<=k;++j){
add_edge((2*j-2)*n+i,(2*j-1)*n+i,val[i]);
if(j<k) add_edge((2*j-2)*n+i,(2*j+1)*n+i,inf);
}
}
for(int i=1,u,v;i<=m;++i){
u=read(),v=read();
E[u].push_back(v);
for(int j=1;j<=k;++j){
add_edge((2*j-1)*n+u,(2*j-2)*n+v,inf);
}
}
queue<int> q;
memset(d,0x3f,sizeof(d));
q.push(s);
while(!q.empty()){
int u=q.front();
q.pop();
for(int v:E[u]){
if(d[v]==inf){
d[v]=d[u]+1;
q.push(v);
}
}
}
if(d[t]<k) return printf("-1\n"),0;
int flow=MF();
if(flow==inf) flow=-1;
printf("%d\n",flow);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3832kb
input:
3 2 5 1 3 1 60 35 1 2 2 3
output:
0
result:
wrong answer Given vertex set from user output does not cover k vertices in some path