"BZOJ5037" [Jsoi2014] telecommunications network DESCRIPTIONJYY created by telecommunications companies, monopoly of the entire Jsoi kingdom's telecommunications network. Jyy built a lot of communication base stations in the Jsoi kingdom. At present, all the base stations are using 2G network system. And now the 3G era has come, jyy in the thinking, should not be some base station to upgrade to 3G network? The Jsoi kingdom can be thought of as an infinitely large two-dimensional plane, with JYY building n communication base stations, and the coordinates of the base station (XI,YI). Each base station has a communication range RI. Base station I will send information to all base stations where the distance does not exceed RI. Each base station upgrade to the 3G network will have a revenue SI, this revenue may be positive (such as the base station near a big city, a lot of users, make a lot of traffic fees), may also be negative (such as the base station around the market is poor, revenue can not fill the upgrade base station itself investment). In addition, since the original base station using 2G network system cannot parse the information from the base station which is upgraded to 3G network system (but the base station after upgrade can parse the information from the non-upgraded base station), therefore, jyy must make, after all the upgrade work is complete, all the base stations using 3G network, The base stations within their communication range are also using 3G networks. Because the number of base stations, you can help jyy calculate, he by upgrading the base station, the maximum amount of revenue can be obtained? Input first line an integer n; next n lines, 4 integers per line, Xi,yi,ri,si, indicates that the communication range of the base station at (Xi,yi) is Ri, and the benefit of the upgrade is Si. The data satisfies the coordinates of any two base stations in different ways. 1≤n≤500,1≤ri≤20000,| xi|,| yi|,| Si|≤10^4. Output
Outputs an integer line that represents the maximum benefit that can be obtained.
Sample Input5
0 1 7 10
0-1 7 10
5 0 1-15
10 0 6 10
1 2-20Sample Output5
"Sample description"
We can upgrade the top three base stations to 3G networks for the best benefit.
Solution: It is obviously a model of the maximum weight closed graph, directly on the map method:
1.s-> the point capacity of all positive weights: the point weight value
2. The point->t capacity of all negative weights: the opposite number of the right value of the point
3. Point > all it can transmit to the point capacity: INF
#include <cstdio> #include <iostream> #include <cstring> #include <queue>using namespace std; int n,cnt,ans,s,t;int X[510],y[510],r[510],s[510];int to[1000000],next[1000000],val[1000000],head[510],d[510]; queue<int> Q;inline Int Rd () {int Ret=0,f=1;char gc=getchar (); while (gc< ' 0 ' | | Gc> ' 9 ') {if (gc== '-') F=-f;gc=getchar ();} while (gc>= ' 0 ' &&gc<= ' 9 ') ret=ret*10+gc-' 0 ', Gc=getchar (); return ret*f;} void Add (int a,int b,int c) {to[cnt]=b,val[cnt]=c,next[cnt]=head[a],head[a]=cnt++;to[cnt]=a,val[cnt]=0,next[cnt]= head[b],head[b]=cnt++;} int dfs (int x,int MF) {if (x==t) return mf;int i,k,temp=mf;for (I=head[x];i!=-1;i=next[i]) {if (d[to[i]]==d[x]+1& &val[i]) {K=dfs (To[i],min (val[i],temp)), if (!k) d[to[i]]=0;val[i]-=k,val[i^1]+=k,temp-=k;if (!temp) break;}} return mf-temp;} int BFs () {while (!q.empty ()) Q.pop () memset (d,0,sizeof (d)); Q.push (S), D[s]=1;int i,u;while (!q.empty ()) {U=q.front (), Q.pop (); for (I=head[u];i!=-1;i=next[i]) {if (!d[to[i]]&&val[i]) {d[to[i]]=d[u]+1;if (to[i]==t) return 1;q.push (To[i]);}} return 0;} int main () {n=rd (), S=0,t=n+1;int I,j;memset (head,-1,sizeof (head)), for (i=1;i<=n;i++) {x[i]=rd (), Y[i]=rd (), r[i]= RD (), s[i]=rd (); if (s[i]>0) Ans+=s[i],add (S,i,s[i]); Elseadd (I,t,-s[i]);} for (i=1;i<=n;i++) {for (j=1;j<=n;j++) if (i!=j&& (X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (Y[i]-y[j]) <= R[i]*r[i]) Add (i,j,1<<30);} while (BFS ()) Ans-=dfs (s,1<<30);p rintf ("%d", ans); return 0;}
"BZOJ5037" [Jsoi2014] maximum power closure of a telecommunications network