QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#442153 | #8740. 科技树 | Jowaire# | WA | 1ms | 5700kb | C++14 | 1.6kb | 2024-06-15 09:22:30 | 2024-06-15 09:22:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+5;
int n,m,p,q,deg[N],a[N];
ll ans=0;
namespace Dinic{
const ll inf=1e14;
int tot=1,head[N],cur[N],S,T,lv[N];
struct edge{
int v,nxt;
ll w;
}e[N<<1];
void add(int u,int v,ll w){
e[++tot]=(edge){v,head[u],w};head[u]=tot;
e[++tot]=(edge){u,head[v],0};head[v]=tot;
}
bool bfs(){
queue<int> Q;
for(int i=S;i<=T;i++) lv[i]=-1;
Q.push(S),lv[S]=1,cur[S]=head[S];
while(!Q.empty()){
int u=Q.front();Q.pop();
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].v;ll w=e[i].w;
if(w&&lv[v]==-1){
lv[v]=lv[u]+1;
cur[v]=head[v];
if(v==T) return true;
Q.push(v);
}
}
}
return false;
}
ll dfs(int u,ll flow){
if(!flow||u==T) return flow;
ll res=flow;
for(int i=cur[u];i&&res>0;i=e[i].nxt){
cur[u]=i;
int v=e[i].v;ll w=e[i].w;
if(w&&lv[v]==lv[u]+1){
ll c=dfs(v,min(res,w));
res-=c,e[i].w-=c,e[i^1].w+=c;
}
}
return flow-res;
}
ll dinic(){
ll res=0;
while(bfs()) res+=dfs(S,inf);
return res;
}
}
using namespace Dinic;
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m>>p>>q;
S=0,T=m+2*n+1;
for(int i=1;i<=n;i++) cin>>a[i],add(i+m,T,a[i]);
for(int i=1,x;i<=n;i++) cin>>x,add(i+m,i+m+n,x),a[i]=min(a[i],x);
for(int i=1,x;i<=m;i++) cin>>x,add(S,i,x),ans+=x;
for(int i=1,u,v;i<=p;i++) cin>>u>>v,add(u,v+m,inf);
for(int i=1,u,v;i<=q;i++) cin>>u>>v,add(u+m+n,v+m,inf),deg[u]++;
for(int i=1;i<=n;i++) if(!deg[i]) add(i+m,T,a[i]);
cout<<ans-dinic()<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5700kb
input:
20 20 106 60 764950822 789804781 628533600 142236215 12714072 356052061 484037108 723775690 717760704 273304732 835189828 150735512 484042916 196657060 269980077 335646130 133320719 575055485 591418974 518146158 692394693 437321875 355893295 101592648 10643103 164010005 81984062 263277829 327687399 ...
output:
1096177542
result:
wrong answer 1st lines differ - expected: '6130508196', found: '1096177542'