QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#288378 | #1359. Setting Maps | Toxic | WA | 1ms | 2992kb | C++14 | 2.0kb | 2023-12-22 16:15:15 | 2023-12-22 16:15:16 |
Judging History
answer
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e3+5;
const int M=1e6+5;
const ll inf=1e18;
struct edge
{
int next,to;
ll fl;
}e[M];
bool vis[N];
int n,m,k,s,t,cnt=1,in[N],cur[N],dep[N];
ll read()
{
ll res,f=1;
char ch;
while((ch=getchar())<'0'||ch>'9')
if(ch=='-')
f=-1;
res=ch^48;
while((ch=getchar())>='0'&&ch<='9')
res=(res<<1)+(res<<3)+(ch^48);
return res*f;
}
void add(int x,int y,ll fl)
{
e[++cnt].next=in[x];
e[cnt].to=y;
e[cnt].fl=fl;
in[x]=cnt;
e[++cnt].next=in[y];
e[cnt].to=x;
e[cnt].fl=0;
in[y]=cnt;
}
bool bfs()
{
int u,i,d;
queue<int> q;
memcpy(cur,in,sizeof(in));
memset(dep,0x3f3f3f3f,sizeof(dep));
q.push(s);dep[s]=0;
while(q.size())
{
u=q.front();q.pop();vis[u]=0;
for(i=in[u];i;i=e[i].next)
{
d=e[i].to;
if(dep[d]>dep[u]+1&&e[i].fl)
{
dep[d]=dep[u]+1;
if(!vis[d])
{
q.push(d);
vis[d]=1;
}
}
}
}
return dep[t]!=0x3f3f3f3f;
}
ll dfs(int u,ll low)
{
if(u==t||!low)
return low;
int i,d;
ll rlow,used=0;
for(i=cur[u];i;i=e[i].next)
{
cur[u]=i;d=e[i].to;
if(dep[d]==dep[u]+1&&e[i].fl)
if((rlow=dfs(d,min(low-used,e[i].fl))))
{
e[i].fl-=rlow;
e[i^1].fl+=rlow;
used+=rlow;
if(used==low)
break;
}
}
return used;
}
ll dinic()
{
ll ans=0;
while(bfs())
ans+=dfs(s,inf<<1);
return ans;
}
int main()
{
int i,j,y,hp;
ll x;
n=read();m=read();k=read();s=read();t=read();hp=2*n;
for(i=1;i<=n;i++)
{
x=read();
for(j=0;j<=k-1;j++)
{
add(j*hp+i,j*hp+n+i,x);
if(j)
add((j-1)*hp+i,j*hp+n+i,inf);//weak restriction
if(j>1)
add(i,j*hp+n+i,inf);//strong restriction
}
}
for(i=1;i<=m;i++)
{
x=read();y=read();
for(j=0;j<=k-1;j++)
add(j*hp+n+x,j*hp+y,inf);
}
t+=(k-1)*hp+n;
x=dinic();
if(x<inf)
printf("%lld",x);
else
printf("-1");
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 2872kb
input:
3 2 5 1 3 1 60 35 1 2 2 3
output:
-1
result:
ok answer = IMPOSSIBLE
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 2992kb
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:
39
result:
wrong answer Integer parameter [name=p; number of vertices] equals to 39, violates the range [-1, 7]