The topic is about N personal 22 to play, ask how to arrange a few games win or lose make a win B,b win c,c a This kind of scissors stone cloth ternary group most.
This is a good god.
- First, the triples have a total of $c_n^3$
- Then consider minimizing the number of triples that do not meet the conditions of the scissors stone cloth:
- For three man-made scissors stone cloth phenomenon, when and only if, one of the people to win the other two people
- And since this is a complete picture, if a person wins the $x_i$ field then contains this person does not satisfy the shear stone cloth phenomenon The ternary group has $c_{x_i}^2$ a
- So the goal is to minimize $\sum c_{x_i}^2$, which is $\sum x_i^2-c_n^2$, where the $c_n^2$ is constant can be taken away
- Consider using the minimum cost maximum flow solution, the source point-race-person-meeting point such a connection edge:
- The source point to the side of each match is the capacity 1 cost 0
- Match to the side of the person is Volume 1 cost 0
- And people to the meeting point, according to the target type, if the flow is $f$, then the cost is $f^2$, the solution is to connect the capacity 1 of the cost is 1, 3, 5, 7, 9 ... 's Side!
- This completes the composition.
1#include <cstdio>2#include <cstring>3#include <queue>4#include <algorithm>5 using namespacestd;6 #defineINF (1<<30)7 #defineMAXN 111118 #defineMAXM 111111*49 structedge{Ten intU,v,cap,cost,next; One }EDGE[MAXM]; A intVS,VT,NV,NE,HEAD[MAXN]; - voidAddedge (intUintVintCapintCost ) { -Edge[ne].u=u; Edge[ne].v=v; Edge[ne].cap=cap; edge[ne].cost=Cost ; theEdge[ne].next=head[u]; head[u]=ne++; -Edge[ne].u=v; Edge[ne].v=u; edge[ne].cap=0; edge[ne].cost=-Cost ; -EDGE[NE].NEXT=HEAD[V]; head[v]=ne++; - } + intD[MAXN],PRE[MAXN]; - BOOLVIS[MAXN]; + BOOLSPFA () { A for(intI=0; i<nv; ++i) { atD[i]=inf; vis[i]=0; - } -d[vs]=0; vis[vs]=0; -queue<int>que; - Que.push (VS); - while(!Que.empty ()) { in intu=Que.front (); Que.pop (); - for(intI=head[u]; i!=-1; I=Edge[i].next) { to intv=edge[i].v; + if(Edge[i].cap && d[v]>d[u]+edge[i].cost) { -d[v]=d[u]+Edge[i].cost; thepre[v]=i; * if(!Vis[v]) { $vis[v]=1;Panax Notoginseng Que.push (v); - } the } + } Avis[u]=0; the } + returnd[vt]!=INF; - } $ intMCMF () { $ intres=0; - while(SPFA ()) { - intflow=inf,cost=0; the for(intU=VT; U!=vs; u=edge[pre[u]].u) { -flow=min (flow,edge[pre[u]].cap);Wuyi } the for(intU=VT; U!=vs; u=edge[pre[u]].u) { -edge[pre[u]].cap-=flow; Wuedge[pre[u]^1].cap+=flow; -cost+=flow*Edge[pre[u]].cost; About } $res+=Cost ; - } - returnRes; - } A intans[111][111]; + intMain () { the intN,a; -scanf"%d",&n); $Vs=n*n+n; vt=vs+1; nv=vt+1; Ne=0; thememset (head,-1,sizeof(head)); the for(intI=0; i<n; ++i) { the intcost=1; the for(intj=1; j<=n; ++j) { -Addedge (N*N+I,VT,1, cost); incost+=2; the } the } About for(intI=0; i<n; ++i) { the for(intj=0; j<n; ++j) { thescanf"%d",&a); the if(I>=J)Continue; +Addedge (Vs,i*n+j,1,0); - if(a==1){ theAddedge (I*n+j,n*n+i,1,0);Bayi}Else if(a==0){ theAddedge (I*n+j,n*n+j,1,0); the}Else{ -Addedge (I*n+j,n*n+i,1,0); -Addedge (I*n+j,n*n+j,1,0); the } the } the } theprintf"%d\n", N (n1) * (n2)/6-(MCMF ()-(n1) *n/2)/2); - for(intx=0; x<n; ++x) { the for(inty=x+1; y<n; ++y) { the for(intI=head[x*n+y]; i!=-1; I=Edge[i].next) { the if(i&1|| EDGE[I].CAP)Continue;94 if(edge[i].v==x+n*N) { theans[x][y]=1; ans[y][x]=0; the}Else{ theans[x][y]=0; ans[y][x]=1;98 } About } - }101 }102 for(intI=0; i<n; ++i) {103 for(intj=0; j<n; ++J) printf ("%d", Ans[i][j]);104Putchar ('\ n'); the }106 return 0;107}
BZOJ2597 [Wc2007] scissors stone cloth (minimum cost maximum flow)