Test instructions
Give n the position where the bombs can be placed (each position is a point on a two-dimensional plane), each time the bomb is placed can only select one of the pair of points, each bomb explosion radius is the same, the radius of the control explosion so that all the explosion range does not intersect (can be tangent), to solve the maximum radius.
Train of thought: Two minute radius, build a plan again 2-sat to have no solution.
Harvest: The original Tarjan execution, in the same strong connected component of the low[] is not necessarily the same, I thought must be the same, directly with low to determine whether in a strong connectivity inside.
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include < cmath>using namespace Std;const int N = 222;int head[n];int n;struct edge{int v,next;} Es[n*n];struct p{double x, y;} Poi[n];const double esp = 1e-6;int tmp[n],dfn[n],low[n],belong[n],scc,sta[n];int cnt,index,top;double dis (int u,int v) { return sqrt ((poi[u].x-poi[v].x) * (poi[u].x-poi[v].x) + (POI[U].Y-POI[V].Y) * (POI[U].Y-POI[V].Y));} void Tarjan (int u) {tmp[u]=1; Dfn[u]=low[u]=++index; Sta[++top]=u; for (int i=head[u];~i;i=es[i].next) {int v=es[i].v; if (tmp[v]==0) Tarjan (v); if (tmp[v]==1) low[u]=min (Low[u],low[v]); } if (Low[u]==dfn[u]) {scc++; do {int v=sta[top]; tmp[v]=2; BELONG[V]=SCC; }while (Sta[top--]!=u); }}void init () {memset (head,-1,sizeof (head)); top=index=cnt=scc=0; memset (tmp,0,sizeof (TMP));} void inline Add_edge (int u,int v) {es[cnt].v=v; Es[Cnt].next=head[u]; head[u]=cnt++;} void build (int u,int v,double R) {if (DIS (u,v) <2*r) Add_edge (u,v^1), Add_edge (v,u^1);} BOOL OK (double R) {init (); for (int i=0;i<n;i++) for (int j=i+1;j<n;j++) {int u=i*2,v=j*2; Build (U,v,r); Build (U,v^1,r); Build (U^1,v,r); Build (U^1,v^1,r); } for (int i=0;i<2*n;i++) if (tmp[i]==0) Tarjan (i); for (int i=0;i<2*n;i++) if (Belong[i]==belong[i^1]) return false; return true;} int main () {while (~SCANF ("%d", &n)} {for (int i=0;i<n;i++) {int a=2*i; scanf ("%lf%lf%lf%lf", &poi[a].x,&poi[a].y,&poi[a^1].x,&poi[a^1].y); } double lb=0,ub=4e4; while (UB-LB>ESP) {double mid= (UB+LB)/2.0; if (OK (mid)) Lb=mid; else Ub=mid; } printf ("%.2f\n", lb); } return 0;}
HDU 3622 Bomb Game (two minutes +2-sat)