QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#283331 | #1359. Setting Maps | blln | WA | 3ms | 24188kb | C++14 | 2.0kb | 2023-12-14 14:44:32 | 2023-12-14 14:44:32 |
Judging History
answer
#include<cstdio>
const long long N=5e5+5,Mx=2e9;
long long n,m,K,l,r,Nr=0,o=1,ST,ED,st,ed,p,q,v,s=0,ans=0,Ans=0,D[N],F[N],NXT[N],LAST[N],NUM[N],A[N],Xr[N],Yr[N],d[N],nxt[N],num[N],last[N],c[N],w[N];bool vis[N];
long long Min(long long t1,long long t2){return t1<t2?t1:t2;}
void Add(long long t1,long long t2,long long t3,long long t4){
o++;nxt[o]=t2;last[o]=num[t1];num[t1]=o;c[o]=t3;w[o]=t4;
o++;nxt[o]=t1;last[o]=num[t2];num[t2]=o;c[o]=0;w[o]=0-t4;
}
long long ss(long long x,long long y){
if(x==ed){ans+=y;Ans+=y*d[st];return y;}
long long h=y,z;vis[x]=true;
for(long long i=num[x];i;i=last[i]){
if(h<=0)break;
if(!vis[nxt[i]]&&c[i]>0&&d[nxt[i]]+w[i]==d[x]){
z=ss(nxt[i],Min(c[i],h));
h-=z;c[i]-=z;c[i^1]+=z;
}
}
return y-h;
}
bool ll(){
long long mi=Mx;
for(long long i=1;i<=n;i++)if(vis[i])
for(long long j=num[i];j;j=last[j])
if(!vis[nxt[j]]&&c[j]>0&&d[nxt[j]]+w[j]-d[i]<mi)mi=d[nxt[j]]+w[j]-d[i];
if(mi==Mx)return false;
for(long long i=1;i<=n;i++)if(vis[i])d[i]+=mi;
return true;
}
int main(){
// freopen("ex_apers3.in","r",stdin);
// freopen("ex_apers3.out","w",stdout);
scanf("%lld %lld %lld",&n,&m,&K);scanf("%lld %lld",&ST,&ED);
for(long long i=1;i<=n;i++)scanf("%lld",&A[i]),F[i]=Mx;F[ST]=1;
for(long long i=1;i<=m;i++)scanf("%lld %lld",&Xr[i],&Yr[i]),NXT[i]=Yr[i],LAST[i]=NUM[Xr[i]],NUM[Xr[i]]=i;
l=0;r=1;D[r]=ST;while(l<r){l++;for(int i=NUM[D[l]];i;i=LAST[i])if(F[D[l]]+1<F[NXT[i]]){F[NXT[i]]=F[D[l]]+1;r++;D[r]=NXT[i];}}if(F[ED]<K){printf("-1");return 0;}
for(long long i=1;i<=K;i++,Nr+=n<<1){for(long long j=1;j<=m;j++)Add(Nr+Xr[j]+n,Nr+Yr[j],Mx,0);for(long long j=1;j<=n;j++)Add(Nr+j,Nr+j+n,A[j],0),i<K?Add(Nr+j,Nr+j+n*3,Mx,0):void();}
st=Nr+1;ed=Nr+2;Add(st,ST,Mx,0);Add(ED+Nr-n,ed,Mx,0);n=Nr+2;
do{
do{
for(long long i=1;i<=n;i++)vis[i]=false;
}while(ss(st,Mx));
}while(ll());
printf("%lld",ans==Mx?-1:ans);
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 15848kb
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: 3ms
memory: 24188kb
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]