QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#321808 | #1359. Setting Maps | ciuim | WA | 1ms | 7852kb | C++14 | 2.5kb | 2024-02-05 16:58:12 | 2024-02-05 16:58:13 |
Judging History
answer
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <unordered_map>
#define ll long long
#define reg register
#define fo(a,b,c) for(reg ll a=b;a<=c;a++)
#define re(a,b,c) for(reg ll a=b;a>=c;a--)
#define pii pair<ll,ll>
#define fi first
#define pb push_back
#define se second
#define mod 1000000009
#define inf 9999999999999
using namespace std;
inline ll gi()
{
ll x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
const int N=500005;
ll s,t;
ll cnt,head[30005],dep[30005],cur[30005];
struct IO
{
ll u,v,w;
}node[N];
queue<ll> q;
ll bfs()
{
memset(dep,0,sizeof(dep));
q.push(s);
dep[s]=1;
while(!q.empty())
{
ll u=q.front();
q.pop();
for(ll i=head[u];i;i=node[i].u)
{
ll v=node[i].v;
if(!dep[v]&&node[i].w)
{
dep[v]=dep[u]+1;
q.push(v);
}
}
}
return dep[t]!=0;
}
ll dfs(ll u,ll f)
{
if(u==t)
{
return f;
}
ll ttt=f;
for(ll i=cur[u];i;i=node[i].u)
{
cur[u]=i;
ll v=node[i].v;
if(dep[v]==dep[u]+1&&node[i].w>0)
{
ll tmp=dfs(v,min(ttt,node[i].w));
node[i].w-=tmp;
node[i^1].w+=tmp;
ttt-=tmp;
if(!ttt) break;
}
if(!ttt) break;
}
return f-ttt;
}
ll n,m,k;
ll FLOW()
{
ll ans=0;
while(bfs())
{
fo(i,1,(n*2+1)*k*2) cur[i]=head[i];
ans+=dfs(s,inf);
}
if(ans>=inf) ans=-1;
return ans;
}
void add(ll u,ll v,ll w)
{
cnt++;
node[cnt].u=head[u];
head[u]=cnt;
node[cnt].v=v;
node[cnt].w=w;
cnt++;
node[cnt].u=head[v];
head[v]=cnt;
node[cnt].v=u;
node[cnt].w=0;
}
ll c[N],tag[N];
int main()
{
n=gi(),m=gi(),k=gi();
s=gi(),t=gi();
cnt=1;
ll flo=2*n+1;
fo(i,1,n)
{
c[i]=gi();
fo(j,0,k-1)
{
add(j*flo+i*2,j*flo+i*2+1,c[i]);
fo(zz,j+1,k-1)
{
add(j*flo+i*2,zz*flo+i*2+1,inf);
}
}
}
fo(i,1,m)
{
ll x=gi(),y=gi();
fo(j,0,k-1)
{
add(j*flo+x*2+1,j*flo+y*2,inf);
}
}
s=2*s;
t=(k-1)*flo+t*2+1;
ll z=FLOW();
if(z>inf)
{
cout<<-1;
return 0;
}
bfs();
vector<ll> ot;
fo(i,1,n)
{
fo(j,0,k-1)
{
if(dep[j*flo+i*2+1]==0&&dep[j*flo+i*2])
{
tag[i]=1;
}
}
}
fo(i,1,n) if(tag[i]) ot.pb(i);
cout<<ot.size()<<'\n';
for(ll x:ot)
{
cout<<x<<" ";
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7852kb
input:
3 2 5 1 3 1 60 35 1 2 2 3
output:
3 1 2 3
result:
wrong answer Given vertex set from user output does not cover k vertices in some path