QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#486198 | #1359. Setting Maps | Mathew_Miao | WA | 1ms | 8236kb | C++23 | 3.0kb | 2024-07-21 17:32:19 | 2024-07-21 17:32:20 |
Judging History
answer
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<string>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=205;
const int MAXS=2e3+10;
const int MAXM=2e6+10;
const int INF=0x3f3f3f3f;
const long long LINF=0x3f3f3f3f3f3f3f3f;
int n,m,k,S,T;
int s,t,cnt=0;
int idx=1;
int head[MAXS],nxt[MAXM],edg[MAXM],w[MAXM];
inline void add_edge(int x,int y,int __w){
idx++;
nxt[idx]=head[x];
head[x]=idx;
edg[idx]=y;
w[idx]=__w;
}
#define edge(x,y,__w) add_edge(x,y,__w);add_edge(y,x,0);
int dep[MAXS],cur[MAXS];
inline bool bfs(){
memset(dep,0,sizeof(int)*(cnt+1));
queue <int> q;
q.push(s);
dep[s]=1;
while(!q.empty())
{
int x=q.front();
q.pop();
cur[x]=head[x];
for(int i=head[x];i;i=nxt[i])
{
if(!w[i]){
continue;
}
int to=edg[i];
if(!dep[to]){
dep[to]=dep[x]+1;
q.push(to);
}
}
}
return dep[t];
}
int dfs(int x,int flow){
if(x==t){
return flow;
}
int res=0;
for(int i=cur[x];i;i=nxt[i])
{
cur[x]=i;
int to=edg[i];
if((!w[i])||(dep[to]^(dep[x]+1))){
continue;
}
int f=dfs(to,min(flow,w[i]));
w[i]-=f;
w[i^1]+=f;
res+=f;
flow-=f;
if(!flow){
break;
}
}
return res;
}
inline int dinic(){
int flow=0;
while(bfs())
{
flow+=dfs(s,INF);
}
return flow;
}
int a[MAXN];
int in[MAXN][5],out[MAXN][5];
int ans=0;
int Ans[MAXN];
signed main(){
scanf("%d%d%d",&n,&m,&k);
scanf("%d%d",&S,&T);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++)
{
for(int j=0;j<k;j++)
{
cnt++;
in[i][j]=cnt;
cnt++;
out[i][j]=cnt;
edge(out[i][j],in[i][j],a[i]);
}
for(int j=0;j<k-1;j++)
{
edge(in[i][j+1],in[i][j],INF);
edge(out[i][j+1],out[i][j],INF);
edge(out[i][j+1],in[i][j],INF);
}
}
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
for(int j=0;j<k;j++)
{
edge(in[y][j],out[x][j],INF);
}
}
s=out[T][k-1];
t=in[S][0];
if(dinic()>=INF){
puts("-1");
return 0;
}
for(int i=1;i<=n;i++)
{
for(int j=0;j<k;j++)
{
if((!dep[in[i][j]])&&dep[out[i][j]]){
ans++;
Ans[ans]=i;
}
}
}
printf("%d\n",ans);
for(int i=1;i<=ans;i++)
{
printf("%d ",Ans[i]);
}
putchar('\n');
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7792kb
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: 8220kb
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:
3 4 5 6
result:
ok answer = 39
Test #3:
score: 0
Accepted
time: 1ms
memory: 7872kb
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: 7920kb
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: 1ms
memory: 7828kb
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: 1ms
memory: 7852kb
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: 1ms
memory: 7892kb
input:
2 1 5 1 2 10 10 1 2
output:
-1
result:
ok answer = IMPOSSIBLE
Test #8:
score: 0
Accepted
time: 1ms
memory: 8236kb
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: 1ms
memory: 8220kb
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 2
result:
ok answer = 10000000
Test #10:
score: 0
Accepted
time: 0ms
memory: 7972kb
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: 7840kb
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: 0ms
memory: 8204kb
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