QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#282072 | #1359. Setting Maps | Diu | WA | 1ms | 3832kb | C++14 | 1.4kb | 2023-12-11 12:31:18 | 2023-12-11 12:31:19 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=4010,M=100010;
const ll Inf=1e15;
int n,m,k,s,t,c[N];
struct edge{
int v;ll w;int nxt;
}e[M];
int hd[N],now[N],tot=1;
void add(int u,int v,ll w){
e[++tot]={v,w,hd[u]},hd[u]=tot;
}
void Add(int u,int v,ll w){
add(u,v,w),add(v,u,0);
}
int lev[N];
bool bfs(){
memset(lev,0,sizeof(lev));
queue<int> q;
q.push(s),lev[s]=1;
for(;!q.empty();){
int u=q.front();q.pop();
now[u]=hd[u];
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(!lev[v]&&e[i].w){
lev[v]=lev[u]+1;
q.push(v);
}
}
}
return lev[t];
}
ll dfs(int u,ll in){
if(u==t)return in;
ll out=0;
for(int &i=now[u];i;i=e[i].nxt){
int v=e[i].v;
if(!e[i].w||lev[v]!=lev[u]+1)continue;
ll to=dfs(v,min(in,e[i].w));
in-=to,out+=to,e[i].w-=to,e[i^1].w+=to;
if(!in)return out;
}
return out;
}
int vl[N];
signed main(){
scanf("%d%d%d%d%d",&n,&m,&k,&s,&t);
for(int i=1;i<=n;i++){
scanf("%d",&c[i]);
for(int j=0;j<k;j++)Add(j*2*n+i,j*2*n+i+n,c[i]);
for(int j=0;j<k-1;j++)Add(j*2*n+i,(j+1)*2*n+i,Inf);
for(int j=0;j<k-1;j++)Add(j*2*n+i+n,(j+1)*2*n+i+n,Inf);
for(int j=0;j<k-1;j++)Add(j*2*n+i,(j+1)*2*n+i+n,Inf);
}
for(int i=1,u,v;i<=m;i++){
scanf("%d%d",&u,&v);
for(int j=0;j<k;j++)Add(j*2*n+u+n,j*2*n+v,Inf);
}
t+=n+n*2*(k-1);
ll ans=0;
while(bfs())ans+=dfs(s,Inf);
if(ans>=Inf)puts("-1");
else printf("%lld\n",ans);
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3780kb
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: 0ms
memory: 3832kb
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:
39
result:
wrong answer Integer parameter [name=p; number of vertices] equals to 39, violates the range [-1, 7]