QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#282113 | #1359. Setting Maps | Hanghang | WA | 0ms | 26148kb | C++14 | 1.9kb | 2023-12-11 13:43:43 | 2023-12-11 13:43:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+3,INF=(ll)1e18;
ll n,m,k,px[N],py[N],a[N];
bool vis[N];
struct Flow
{
ll tot=1,hd[N],ne[N],to[N],lim[N];
void Add(int x,int y,ll z)
{
ne[++tot]=hd[x];hd[x]=tot;to[tot]=y;lim[tot]=z;
ne[++tot]=hd[y];hd[y]=tot;to[tot]=x;lim[tot]=0;
}
ll T,dis[N],cur[N];
ll Dfs(ll x,ll res)
{
if(x==T)return res;
ll flow=0;
for(int i=cur[x];i&&res;i=ne[i])
{
cur[x]=i;ll w=min(res,lim[i]),y=to[i],z;
if(dis[x]+1==dis[y]&&w)z=Dfs(y,w),flow+=z,res-=z,lim[i]-=z,lim[i^1]+=z;
}
if(!flow)dis[x]=-1;
return flow;
}
ll Maxflow(int s,int t)
{
T=t;ll flow=0;
while(1)
{
queue<int>q;q.push(s);memcpy(cur,hd,sizeof(hd));
memset(dis,-1,sizeof(dis));dis[s]=0;
while(!q.empty())
{
int x=q.front();q.pop();
for(int i=hd[x];i;i=ne[i])if(dis[to[i]]==-1&&lim[i])
dis[to[i]]=dis[x]+1,q.push(to[i]);
}
if(dis[t]==-1)return flow;
flow+=Dfs(s,INF);
}
}
bool v[N];
void Bfs(int x)
{
queue<int>q;v[x]=1;q.push(x);
while(!q.empty())
{
int x=q.front();q.pop();
for(int i=hd[x];i;i=ne[i])
if(!v[to[i]]&&lim[i])v[to[i]]=1,q.push(to[i]);
}
}
}G[6];
int main()
{
cin>>n>>m>>k;ll S,T,ans=0;cin>>S>>T;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)cin>>px[i]>>py[i];
for(int t=1;t<=k;t++)
{
for(int i=1;i<=m;i++)G[t].Add(px[i]+n,py[i],INF);
for(int i=1;i<=n;i++)G[t].Add(i,i+n,vis[i]?INF:a[i]);
if(G[t].Maxflow(S,T+n)>=INF){cout<<-1;return 0;}
G[t].Bfs(S);
for(int i=1;i<=n;i++)if(G[t].v[i]!=G[t].v[i+n])vis[i]=1;
}
for(int i=1;i<=n;i++)if(vis[i])ans+=a[i];
cout<<ans;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 26148kb
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: 0ms
memory: 17996kb
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]