QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#486441 | #1359. Setting Maps | maojun | WA | 3ms | 4048kb | C++23 | 2.0kb | 2024-07-21 20:07:16 | 2024-07-21 20:07:17 |
Judging History
answer
#include<bits/stdc++.h>
#define DEBUG if(0)
using namespace std;
const int N=2005,E=1e5;
int n,m,k,s,t;
int idx=0,S,T,in[N][6],out[N][6];
int tot=1,head[N],to[E],nxt[E],ew[E];
inline void _Add(int u,int v,int w){
DEBUG{
printf("%d %d ",u,v);
if(w==1e9)puts("inf");
else printf("%d\n",w);
}
to[++tot]=v;nxt[tot]=head[u];head[u]=tot;ew[tot]=w;}
inline void Add(int u,int v,int w){_Add(u,v,w);_Add(v,u,0);}
const int O=1e9;
int now[N],dep[N];
inline bool bfs(){
memset(dep,0xff,sizeof dep);dep[S]=0;
queue<int>q;q.push(S);
while(!q.empty()){
int u=q.front();q.pop();
for(int i=now[u]=head[u];i;i=nxt[i])
if(int v=to[i];ew[i]&&!~dep[v]){dep[v]=dep[u]+1;q.push(v);}
}
// for(int i=1;i<=idx;i++)printf("%d ",dep[i]);puts("");
return~dep[T];
}
int dfs(int u,int in){
DEBUG printf("u=%d,in=%d\n",u,in);
if(u==T)return in;
int lst=in;
for(int i=now[u];i&&lst;i=now[u]){
int v=to[i];now[u]=nxt[i];
if(!ew[i]||dep[v]^dep[u]+1)continue;
int f=dfs(v,min(ew[i],lst));
DEBUG printf("f=%d\n",f);
if(!f)dep[v]=-1;
else{ew[i]-=f;ew[i^1]+=f;lst-=f;}
}
return in-lst;
}
int main(){
scanf("%d%d%d%d%d",&n,&m,&k,&s,&t);
static int eid[N][6];
for(int i=1,c;i<=n;i++){
scanf("%d",&c);
for(int j=1;j<=k;j++){
in[i][j]=++idx;out[i][j]=++idx;
// Add(in[i][j],out[i][j],O);
Add(in[i][j],out[i][j],c);//eid[i][j]=tot-1;
}
for(int j=1;j<k;j++){
Add(in[i][j],in[i][j+1],O);
Add(out[i][j],out[i][j+1],O);
Add(in[i][j],out[i][j+1],O);
}
}
for(int u,v;m--;){
scanf("%d%d",&u,&v);
for(int j=1;j<=k;j++)Add(out[u][j],in[v][j],O);
}
S=in[s][1];T=out[t][k];
// printf("S=%d T=%d\n",S,T);
int MF=0;
for(;bfs();)if((MF+=dfs(S,O))>=O){puts("-1");return 0;}
// printf("%d\n",MF);
// DEBUG{for(int i=1;i<=idx;i++)printf("%d ",dep[i]);puts("");}
vector<int>ans;
for(int i=1;i<=n;i++)for(int j=1;j<=k;j++)
if(~dep[in[i][j]]&&!~dep[out[i][j]])ans.emplace_back(i);
// if(!ew[eid[i][j]])ans.emplace_back(i);
printf("%d\n",ans.size());
for(int i:ans)printf("%d ",i);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3692kb
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: 0ms
memory: 3808kb
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: 0ms
memory: 3888kb
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: 0ms
memory: 4048kb
input:
2 2 2 2 1 100 200 1 2 2 1
output:
2 1 2
result:
ok answer = 300
Test #5:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
5 5 5 1 5 1 1 1 1 1 1 2 2 3 3 4 4 5 1 5
output:
-1
result:
ok answer = IMPOSSIBLE
Test #6:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
100 120 5 1 5 5367720 2854323 1799056 9744604 3215334 7580413 6269402 3208439 8812449 3297484 2047196 4044341 7514502 2928715 9335004 3935096 6660663 3356480 4801491 5786147 895995 6710240 222342 4469390 1543213 6678041 8838445 6741919 8138951 5273670 8983795 5131484 4245746 7460466 8357966 8464419 ...
output:
-1
result:
ok answer = IMPOSSIBLE
Test #7:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
2 1 5 1 2 10 10 1 2
output:
-1
result:
ok answer = IMPOSSIBLE
Test #8:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
154 304 2 67 7 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 100000...
output:
2 7 67
result:
ok answer = 20000000
Test #9:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
75 146 1 15 2 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 1000000...
output:
1 15
result:
ok answer = 10000000
Test #10:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
182 360 4 97 110 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 1000...
output:
-1
result:
ok answer = IMPOSSIBLE
Test #11:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
136 268 5 132 5 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000...
output:
-1
result:
ok answer = IMPOSSIBLE
Test #12:
score: -100
Wrong Answer
time: 3ms
memory: 3708kb
input:
200 396 3 174 124 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 100...
output:
-1
result:
wrong answer User answer is not optimal; judge: 2000000000, user: 2000000010