QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282106 | #1359. Setting Maps | SoyTony | WA | 1ms | 3712kb | C++14 | 3.1kb | 2023-12-11 13:34:55 | 2023-12-11 13:34:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=205;
const int maxm=505;
const int inf=0x7f7f7f7f;
inline int read(){
int x=0,w=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*w;
}
int n,m,k;
int s,t;
int val[maxn];
vector<int> E[maxn];
int d[maxn];
int S,T;
struct edge{
int to,nxt,w;
}e[maxn*20+maxm*10];
int head[maxn*10],cnt;
inline void add_edge(int u,int v,int w){
e[++cnt].to=v,e[cnt].nxt=head[u],head[u]=cnt,e[cnt].w=w;
e[++cnt].to=u,e[cnt].nxt=head[v],head[v]=cnt,e[cnt].w=0;
}
int cur[maxn*10],dis[maxn*10];
int dfs(int u,int rest){
if(u==T) return rest;
int flow=0;
for(int i=cur[u],v,w;i&&rest;i=e[i].nxt){
cur[u]=i;
v=e[i].to,w=e[i].w;
if(dis[u]+1==dis[v]&&w){
int k=dfs(v,min(rest,w));
flow+=k,rest-=k;
e[i].w-=k,e[i^1].w+=k;
}
}
if(!flow) dis[u]=-1;
return flow;
}
queue<int> q;
inline int MF(){
int flow=0;
while(1){
memcpy(cur,head,sizeof(head));
memset(dis,-1,sizeof(dis));
dis[S]=0;
q.push(S);
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=head[u],v,w;i;i=e[i].nxt){
v=e[i].to,w=e[i].w;
if(dis[v]==-1&&w){
dis[v]=dis[u]+1;
q.push(v);
}
}
}
if(dis[T]==-1) return flow;
flow+=dfs(S,inf);
}
}
bool mark[maxn*10];
vector<int> ans;
int main(){
// freopen("apers.in","r",stdin);
// freopen("apers.out","w",stdout);
n=read(),m=read(),k=read();
s=read(),t=read();
S=2*k*n+1,T=2*k*n+2;
cnt=1;
add_edge(S,s,inf),add_edge((2*k-1)*n+t,T,inf);
for(int i=1;i<=n;++i){
val[i]=read();
for(int j=1;j<=k;++j){
add_edge((2*j-2)*n+i,(2*j-1)*n+i,val[i]);
if(j<k) add_edge((2*j-2)*n+i,(2*j+1)*n+i,inf);
}
}
for(int i=1,u,v;i<=m;++i){
u=read(),v=read();
E[u].push_back(v);
for(int j=1;j<=k;++j){
add_edge((2*j-1)*n+u,(2*j-2)*n+v,inf);
}
}
queue<int> q;
memset(d,0x7f,sizeof(d));
d[s]=1;
q.push(s);
while(!q.empty()){
int u=q.front();
q.pop();
for(int v:E[u]){
if(d[v]==inf){
d[v]=d[u]+1;
q.push(v);
}
}
}
if(d[t]<k) return printf("-1\n"),0;
MF();
q.push(S);
while(!q.empty()){
int u=q.front();
q.pop();
mark[u]=true;
for(int i=head[u],v,w;i;i=e[i].nxt){
v=e[i].to,w=e[i].w;
if(!mark[v]&&w) q.push(v);
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=k;++j){
if(mark[(2*j-2)*n+i]!=mark[(2*j-1)*n+i]) ans.push_back(i);
}
}
printf("%ld\n",ans.size());
for(int i:ans) printf("%d ",i);
printf("\n");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3520kb
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: 3712kb
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: -100
Wrong Answer
time: 1ms
memory: 3692kb
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:
7 1 5 6 7 8 9 10
result:
wrong answer User answer is not optimal; judge: 60, user: 1060