The most powerful closed sub-graph. The building is ingenious.
Most powerful closed sub-graphs:
#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePi=acos (-1.0), eps=1e-8;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} InlineintRead () {Charc = GetChar (); while(!isdigit (c)) C =GetChar (); intx =0; while(IsDigit (c)) {x = x *Ten+ C-'0'; c =GetChar ();} returnx;}Const intMAXN =30000+Ten;Const intINF =0x7FFFFFFF;structedge{int from, to, cap, flow; Edge (intUintVintCintf): from(U), to (v), Cap (c), Flow (f) {}};vector<Edge>Edges;vector<int>G[MAXN];BOOLVIS[MAXN];intD[MAXN];intCUR[MAXN];intN, m, S, T;voidinit () { for(inti =0; i < MAXN; i++) g[i].clear (); Edges.clear ();}voidAddedge (int from,intTo,intcap) {Edges.push_back (Edge ( from, to, Cap,0)); Edges.push_back (Edge to, from,0,0)); intW =edges.size (); g[ from].push_back (W-2); G[to].push_back (W-1);}BOOLBFS () {memset (Vis,0,sizeof(VIS)); Queue<int>p; Q.push (s); D[s]=0; Vis[s]=1; while(!Q.empty ()) { intx =Q.front (); Q.pop (); for(inti =0; I<g[x].size (); i++) {Edge e=Edges[g[x][i]]; if(!vis[e.to] && e.cap>e.flow) {vis[e.to]=1; D[e.to]= D[x] +1; Q.push (e.to); } } } returnvis[t];}intDFS (intXinta) { if(x = = T | | a = =0) returnA; intFlow =0, F; for(int&i = Cur[x]; I<g[x].size (); i++) {Edge e=Edges[g[x][i]]; if(d[x]+1= = d[e.to]&& (F=dfs (E.to,min (a,e.cap-e.flow)) >0) {Edges[g[x][i]].flow+=F; Edges[g[x][i]^1].flow-=F; Flow+=F; A-=F; if(a==0) Break; } } if(!flow) d[x] =-1; returnflow;}intDinic (intSintt) { intFlow =0; while(BFS ()) {memset (cur,0,sizeof(cur)); Flow+=DFS (S, INF); } returnflow;}Const intmaxm= the;intt,len,a[maxm],b[maxm],w[maxm][maxm],val[2*maxm*Maxm],ans;CharSTR[MAXM];intMain () {scanf ("%d", &t);intcas=1; while(t--) {scanf ("%d", &len); scanf"%s", str); for(intI=0;i<Ten; i++) scanf ("%d%d",&a[i],&B[i]); for(intI=0; i<len;i++) for(intj=0; j<len;j++) scanf ("%d",&W[i][j]); Init (); Ans=0; S=len*len+len+Ten; val[s]=0; T=len*len+len+Ten+1; val[t]=0; for(intI=0; i<len;i++) for(intj=i+1; j<len;j++) {Val[i*len+j]=w[i][j]+W[j][i]; Addedge (i*len+j,len*len+I,inf); Addedge (i*len+j,len*len+J,inf); if(val[i*len+j]>0) Addedge (S,i*len+j,val[i*len+j]), ans=ans+val[i*len+J]; Else if(val[i*len+j]<0) Addedge (i*len+j,t,-val[i*len+J]); } for(inti=len*len;i<=len*len+len-1; i++) {Val[i]=-a[str[i-len*len]-'0']; Addedge (I,len*len+len+str[i-len*len]-'0', INF); if(val[i]>0) Addedge (S,i,val[i]), ans=ans+Val[i]; Else if(val[i]<0) Addedge (i,t,-Val[i]); } for(inti=len*len+len;i<=len*len+len+Ten-1; i++) {Val[i]=-b[i-(Len*len+len)]+a[i-(len*len+Len)]; if(val[i]>0) Addedge (S,i,val[i]), ans=ans+Val[i]; Else if(val[i]<0) Addedge (i,t,-Val[i]); } ans=ans-dinic (s,t); printf ("Case #%d:%d\n", cas++, ans); } return 0;}
HDU 5772 String problem