套个模板都整了好几天…..尴尬
There are NN bombs needing exploding.
Each bomb has three attributes: exploding radius riri, position (xi,yi)(xi,yi) and lighting-cost cici which means you need to pay cici cost making it explode.
If a un-lighting bomb is in or on the border the exploding area of another exploding one, the un-lighting bomb also will explode.
Now you know the attributes of all bombs, please use the minimum cost to explode all bombs.
Input
First line contains an integer TT, which indicates the number of test cases.
Every test case begins with an integers NN, which indicates the numbers of bombs.
In the following NN lines, the ith line contains four intergers xixi, yiyi, riri and cici, indicating the coordinate of ith bomb is (xi,yi)(xi,yi), exploding radius is riri and lighting-cost is cici.
Limits
- 1≤T≤201≤T≤20
- 1≤N≤10001≤N≤1000
- −108≤xi,yi,ri≤108−108≤xi,yi,ri≤108
- 1≤ci≤1041≤ci≤104
Output
For every test case, you should output ‘Case #x: y’, where x indicates the case number and counts from 1 and y is the minimum cost.
Sample Input
1
5
0 0 1 5
1 1 1 6
0 1 1 7
3 0 2 10
5 0 1 4
Sample Output
Case #1: 15
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#define INF 1e16
using namespace std;
typedef long long ll;
const int maxn=1005;
int n,tot;
ll x[maxn],y[maxn],r[maxn],c[maxn];
ll Bcnt,Top,Index; /// 强连通分量的个数;
ll low[maxn], dfn[maxn],in0[maxn];
ll belong[maxn], stack[maxn],head[maxn];
bool instack[maxn];
struct node1
{
ll to,next;
} G[maxn*maxn];
struct node2
{
ll x,y,r,val;
}point[maxn];
void add(int u,int v)
{
G[tot].to=v;
G[tot].next=head[u];
head[u]=tot++;
};
void Init_tarjan()
{
Bcnt=Top=Index=0;
memset(low,0,sizeof(low));
memset(dfn,0,sizeof(dfn));
memset(head,-1,sizeof(head));
memset(instack,0,sizeof(instack));
memset(belong,0,sizeof(belong));
memset(stack,0,sizeof(stack));
memset(in0,0,sizeof(in0));
}
void Tarjan(int u)
{
stack[Top++]= u;
instack[u]= 1;
low[u]= dfn[u]= ++Index;
for(int i=head[u]; i!=-1; i=G[i].next)
{
int v= G[i].to;
if( !dfn[v] )
{
Tarjan(v);
low[u]= min( low[v], low[u] );
}
else if( instack[v] )
low[u]= min( low[u], dfn[v] );
}
if( low[u]==dfn[u] )
{
++Bcnt;
int v;
do
{
v= stack[--Top];
instack[v]= 0;
belong[v]= Bcnt;
}
while( u!=v );
}
}
int main()
{
int t;
int ph=1;
scanf("%d",&t);
while(t--)
{
tot=0;
Init_tarjan();
scanf("%d",&n);
for(int i=0; i<n; i++)
scanf("%lld%lld%lld%lld",&point[i].x,&point[i].y,&point[i].r,&point[i].val);
for(int i=0; i<n; i++)
for(int j=i+1; j<n; j++)
{
ll dis=(point[i].x-point[j].x)*(point[i].x-point[j].x)+(point[i].y-point[j].y)*(point[i].y-point[j].y);
if(dis<=point[i].r*point[i].r) add(i,j);
if(dis<=point[j].r*point[j].r) add(j,i);
}
for(int i=0; i<n; i++)
{
if(dfn[i]==0)
Tarjan(i);
}
for(int u=0; u<n; u++)
{
for(int i=head[u]; i!=-1; i=G[i].next)
{
int to=G[i].to;
if(belong[u]!=belong[to])
{
in0[belong[to]]++;
}
}
}
ll ans=0;
for(int i=1; i<=Bcnt; i++)
{
if(in0[i]==0)
{
ll minn=INF;
for(int u=0; u<n; u++)
{
if(belong[u]==i)
{
minn=min(minn,point[u].val);
}
}
ans+=minn;
}
}
printf("Case #%d: ",ph++);
printf("%lld\n",ans);
}
}