QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#487166 | #1359. Setting Maps | jiaziqi | WA | 1ms | 7036kb | C++14 | 1.9kb | 2024-07-22 17:17:46 | 2024-07-22 17:17:48 |
Judging History
answer
#include<bits/stdc++.h>
#define ShuaiBi main
using namespace std;
typedef long long ll;
const int N=1e5+3,M=2e5+3;
const ll inf=0x3f3f3f3f3f3f3f3f;
struct edge{
int to,next;
ll w;
}e[M<<1];
int head[N],ecnt=-1;
void add_edge(int u,int v,ll w){
e[++ecnt].to=v; e[ecnt].next=head[u]; e[ecnt].w=w; head[u]=ecnt;
e[++ecnt].to=u; e[ecnt].next=head[v]; e[ecnt].w=0; head[v]=ecnt;
}
int now[N],n,nn,m,k,s,t;
ll dis[N],cnt,sum,Ans;
bool bfs(){
queue<int> q;
memset(dis,0x3f,sizeof(dis));
q.push(s),now[s]=head[s],dis[s]=0;
while(!q.empty()){
int x=q.front();
q.pop();
for(int i=head[x];~i;i=e[i].next){
if(e[i].w>0 && dis[e[i].to]==inf){
dis[e[i].to]=dis[x]+1;
now[e[i].to]=head[e[i].to];
q.push(e[i].to);
if(e[i].to==t) return 1;
}
}
}
return 0;
}
ll dfs(int x,ll flow){
if(x==t) return flow;
ll k,res=0;
for(int i=now[x];~i && flow;i=e[i].next){
now[x]=i;
if(e[i].w>0 && dis[e[i].to]==dis[x]+1){
k=dfs(e[i].to,min(e[i].w,flow));
if(k==0) dis[e[i].to]=inf;
e[i].w-=k,e[i^1].w+=k;
flow-=k,res+=k;
}
}
return res;
}
ll dicnic(){
ll ans=0;
while(bfs()) ans+=dfs(s,inf);
return ans;
}
bool boom[N];
int ShuaiBi(){
memset(head,-1,sizeof(head));
scanf("%d%d%d%d%d",&n,&m,&k,&s,&t);
nn=2*n+1;
for(int i=1,x;i<=n;i++){
scanf("%d",&x),sum+=x;
for(int j=0;j<k;j++){
add_edge(i+j*nn,i+n+j*nn,x);
for(int p=j+1;p<k;p++) add_edge(i+j*nn,i+n+p*nn,inf);
}
}
for(int i=1,u,v;i<=m;i++){
scanf("%d%d",&u,&v);
for(int j=0;j<k;j++) add_edge(u+n+j*nn,v+j*nn,inf);
}
t=t+n+(k-1)*nn;
if(sum<(Ans=dicnic())) return puts("-1"),0;
bfs();
for(int i=1;i<=n;i++)
for(int j=0;j<k;j++)
if(dis[i+j*nn]!=inf && dis[i+n+j*nn]==inf) cnt+=(!boom[i]),boom[i]=1;
printf("%lld\n",cnt);
for(int i=1;i<=t;i++) if(boom[i]) printf("%d ",i);
putchar('\n');
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6288kb
input:
3 2 5 1 3 1 60 35 1 2 2 3
output:
-1
result:
ok answer = IMPOSSIBLE
Test #2:
score: 0
Accepted
time: 1ms
memory: 6076kb
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:
4 2 3 4 5
result:
ok answer = 39
Test #3:
score: 0
Accepted
time: 1ms
memory: 6208kb
input:
11 17 2 1 11 1000 10 10 10 10 10 10 10 10 10 1000 1 2 1 3 1 4 1 5 1 6 2 7 3 7 4 7 5 8 6 8 7 8 7 9 7 10 8 9 8 11 9 11 10 11
output:
6 5 6 7 8 9 10
result:
ok answer = 60
Test #4:
score: 0
Accepted
time: 1ms
memory: 7036kb
input:
2 2 2 2 1 100 200 1 2 2 1
output:
2 1 2
result:
ok answer = 300
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 6604kb
input:
5 5 5 1 5 1 1 1 1 1 1 2 2 3 3 4 4 5 1 5
output:
2 1 5
result:
wrong answer Given vertex set from user output does not cover k vertices in some path