QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#674477 | #9102. Zayin and Elements | ucup-team5071# | WA | 2ms | 3640kb | C++20 | 2.2kb | 2024-10-25 15:57:47 | 2024-10-25 15:57:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=205,M=3005;
struct SSP{
int cnt=1,hd[N],nxt[M<<1],to[M<<1],limit[M<<1],cst[M<<1];
void init(){
memset(hd,0,sizeof(hd));
cnt=1;
}
void add(int u,int v,int w,int c){
//cout<<u<<" "<<v<<" "<<w<<" "<<c<<endl;
nxt[++cnt]=hd[u],hd[u]=cnt,to[cnt]=v,limit[cnt]=w,cst[cnt]=c;
nxt[++cnt]=hd[v],hd[v]=cnt,to[cnt]=u,limit[cnt]=0,cst[cnt]=-c;
}
int fr[N],fl[N],in[N],dis[N];
pair<int,int> min_cost(int s,int t){
int flow=0,cost=0;
while(true){
queue<int> q;
memset(dis,0x3f,sizeof(dis));
memset(in,0,sizeof(in));
fl[s]=1e9,dis[s]=0,q.push(s);
while(!q.empty()){
int cur=q.front();
q.pop();in[cur]=0;
for(int i=hd[cur];i;i=nxt[i]){
int it=to[i],d=dis[cur]+cst[i];
// cout<<"i="<<i<<" it="<<it<<endl;
if(limit[i]&&d<dis[it]){
fl[it]=min(limit[i],fl[cur]),fr[it]=i,dis[it]=d;
if(!in[it])in[it]=1,q.push(it);
}
}
}
if(dis[t]>1e9)return {flow,cost};
flow+=fl[t],cost+=dis[t]*fl[t];
for(int u=t;u!=s;u=to[fr[u]^1])limit[fr[u]]-=fl[t],limit[fr[u]^1]+=fl[t];
}
}
}Sol;
void Solve(){
int n,m;
cin>>n>>m;
Sol.init();
int s=m*2+n+1,t=m*2+n+2;
int res=0;
for(int i=1;i<=n;i++)
Sol.add(2*m+i,t,1,0);
for(int i=1;i<=m;i++){
int a,b,c,t;
cin>>a>>b>>c>>t;
Sol.add(s,i,(int)1e9,0);
res+=(b+c)*2;
Sol.add(i,i+m,a,0);
for(int j=1;j<=b*2;j++)
Sol.add(i,i+m,1,1);
for(int j=1;j<=c;j++)
Sol.add(i,i+m,1,2);
for(int j=1;j<=t;j++){
int x;
cin>>x;
Sol.add(i+m,2*m+x,1,0);
}
}
pair<int,int> now=Sol.min_cost(s,t);
if(now.first<n)cout<<"-1"<<"\n";
else cout<<(res-now.second)/2<<"\n";
}
int main(){
//ios::sync_with_stdio(false),cin.tie(0);
int T;
cin>>T;
while(T--)Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3620kb
input:
2 5 2 2 3 1 2 3 1 1 1 1 3 4 5 2 5 2 2 3 1 1 3 1 0 1 2 1 2
output:
5 -1
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3640kb
input:
5 9 10 0 0 10 2 3 8 0 0 10 2 4 6 0 8 2 2 2 4 0 0 10 3 1 3 8 0 4 6 2 2 3 0 8 2 3 2 6 7 0 9 1 2 1 7 0 2 8 3 1 4 9 0 7 3 1 5 0 0 10 3 5 6 9 3 10 0 9 1 1 2 0 5 5 1 1 0 1 9 1 1 0 7 3 1 1 0 7 3 0 0 0 10 0 0 6 4 1 3 0 9 1 0 0 7 3 0 0 9 1 1 2 90 20 0 6 4 12 1 4 5 22 32 64 66 67 73 87 88 89 0 1 9 12 3 8 21 3...
output:
95 98 155 151 152
result:
wrong answer 1st lines differ - expected: '94', found: '95'