题目
题意: 略。
思路: 这个拆点好想,没看题解就想出来了。每个冰块作为一个点,企鹅乱跳作为不同点之间的流量,然后每个冰块的跳跃次数的用拆点的方式限制住。之后枚举汇点得到答案,记得每次枚举之前把网络重置,每条正向边的边权应该是现有边权+反向边的边权,还能流多少+已经流了多少=总共能流多少=容量,反向边的边权清0,变成没流的状态。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 222;
const int M = 2*(N*N*2);
const int INF = 1e8;
typedef long long ll;
int cur[N],d[N],q[N];
int h[N],e[M],ne[M],w[M],idx = 0;
int n,m,T; int st,ed;
double k;
int tot = 0;
void add(int a,int b,int c)
{
e[idx] = b,w[idx] = c,ne[idx] = h[a],h[a] = idx++;
e[idx] = a,w[idx] = 0,ne[idx] = h[b],h[b] = idx++;
}
bool bfs()
{
int hh = 0,tt = 0;
memset(d,-1,sizeof(d));
d[st] = 0,cur[st] = h[st],q[tt++] = st;
while(hh!=tt)
{
int u = q[hh++];
for(int i=h[u];~i;i=ne[i])
{
int j = e[i];
if(d[j]==-1&&w[i])
{
d[j] = d[u]+1;
cur[j] = h[j];
if(j==ed) return 1;
q[tt++] = j;
}
}
}
return 0;
}
ll find(int u,ll limit)
{
if(u==ed) return limit;
ll flow = 0;
for(int i=cur[u];~i&&flow<limit;i=ne[i])
{
int j = e[i];
cur[u] = i; //当前弧优化
if(d[j]==d[u]+1&&w[i])
{
ll t = find(j,min(1ll*w[i],limit-flow));
if(!t) d[j] = -1;
flow += t,w[i] -= t,w[i^1] += t;
}
}
return flow;
}
ll dinic()
{
ll ans = 0,flow;
while(bfs()) while(flow = find(st,INF)) ans += flow;
return ans;
}
struct node{
int x;
int y;
int cnt; //多少个企鹅
int r; //最多跳多少次
}a[N];
bool check(int i,int j) //是否能跳
{
double t = 1.0*(a[j].y-a[i].y)*(a[j].y-a[i].y) + 1.0*(a[j].x-a[i].x)*(a[j].x-a[i].x);
double t2 = 1.0*k*k;
return t<=t2;
}
void solve()
{
st = N-1;
memset(h,-1,sizeof(h)); idx = 0; tot = 0;
cin>>n>>k;
for(int i=0;i<n;++i)
{
int x,y,z,z2; cin>>x>>y>>z>>z2;
a[i] = {x,y,z,z2};
add(i,i+n,z2); //入点向出点连边,限制最多跳多少次
add(st,i,z); //源点向入点连边,有多少只企鹅
tot += z;
}
for(int i=0;i<n;++i)
{
for(int j=i+1;j<n;++j)
{
// if(i==j) continue;
if(check(i,j))
{
add(i+n,j,INF); //可以互相跳
add(j+n,i,INF);
}
}
}
vector<int> res;
ll sum = 0;
for(ed = 0;ed < n;++ed)
{
for(int i=0;i<idx;i+=2)
{
w[i] = w[i] + w[i^1];
w[i^1] = 0;
}
sum = dinic();
// cout<<ed<<":"<<sum<<"\n";
if(sum == tot) res.push_back(ed);
}
if(res.size()==0)
{
cout<<-1;
}
else
{
for(int &j:res) cout<<j<<" ";
}
cout<<"\n";
}
int main(void)
{
cin>>T;
while(T--)
solve();
return 0;
}
/*
2
5 3.5
1 1 1 1
2 3 0 1
3 5 1 1
5 1 1 1
5 4 0 1
3 1.1
-1 0 5 10
0 0 3 9
2 0 1 1
*/