| F.a.qs |
Home |
discuss |
Problemset |
Status |
ranklist |
Contest |
modifyuser hyxzc |
Logout |
Donate this site |
Notice: Since this OJ is built under the Linux platform, and many of the data are produced under Windows, please note the input, output statements and data types and ranges to avoid unnecessary re appearance. 1934: [Shoi2007]vote Goodwill Poll time limit:1 Sec Memory limit:64 MB
submit:1646 solved:1006
[Submit] [Status] [Discuss] Description Kindergarten There are N children planning to vote to decide whether to sleep or nap. To them, the problem is not very important, so they decided to carry forward the spirit of humility. Although everyone has their own ideas, but in order to take care of their friends of the idea, they can also vote and their own will be contrary to the vote. We define the number of conflicts in a poll as the total number of conflicts between good friends plus the number of people who have clashed with their own intentions. Our question is, how should each child vote in order to minimize the number of conflicts? The first line of input is only two integers n,m, guaranteed to have 2≤n≤300,1≤m≤n (n-1)/2. where n represents the total number of people, M is the logarithm of good friends. The second line of the file has n integers, and the first integer represents the will of the child I, and when it is 1, it expresses its consent to sleep, while it is 0 when it stands against sleep. The next file also has m lines, each with two integer i,j. Indicates that I,j is a good friend, and we guarantee that no two pairs of i,j will repeat. Output requires only one integer, which is the smallest possible number of collisions. Sample Input3 3
1 0 0
1 2
1 3
3 2
Sample Output1HINT
In the first example, all the children voted for the best solution.
Exercises
Connect points with S, T points, weights of 1 or 0, path edge, maximum flow
Code:
1#include <cstdio>2#include <queue>3#include <cstring>4 #defineMAXN 3105#include <iostream>6 7 using namespacestd;8 9 ints=0, t,head[maxn],dis[maxn],maxlow,ans,cnt=1, N,M,X[MAXN];Ten structSS One { A intto ; - intNext; - intEdge; the}e[130100]; - - voidAddintUintVintW) - { +e[++cnt].next=Head[u]; -head[u]=CNT; +e[cnt].to=v; AE[cnt].edge=W; at } - - voidInsertintUintVintW) - { - Add (u,v,w); -Add (V,u,0); in } - to BOOLBFS () + { - for(intI=1; i<=t;i++) dis[i]=0x7fffffff; thequeue<int>que; * Que.push (S); $dis[0]=0;Panax Notoginseng while(!que.empty ()) - { the intnow=Que.front (); + Que.pop (); A for(intI=head[now];i;i=e[i].next) the if(e[i].edge&&dis[e[i].to]>dis[now]+1) + { -dis[e[i].to]=dis[now]+1; $ Que.push (e[i].to); $ if(e[i].to==t)return 1; - } - } the return 0; - } Wuyi the intDinic (intXintinf) - { Wu if(x==t)returninf; - intrest=inf; About for(intI=head[x];i&&rest;i=e[i].next) $ if(e[i].edge&&dis[e[i].to]==dis[x]+1) - { - intnow=dinic (E[i].to,min (Rest,e[i].edge)); - if(!now) dis[now]=0; Ae[i].edge-=Now ; +e[i^1].edge+=Now ; therest-=Now ; - } $ returninf-rest; the } the the intMain () the { -scanf"%d%d",&n,&m); int=n+1; the for(intI=1; i<=n;i++) the { About intx; thescanf"%d",&x); the if(x) theInsert0I1), insert (I,t,0); + Else -Insert (I,t,1), insert (0I0); the }Bayi for(intI=1; i<=m;i++) the { the intu,v; -scanf"%d%d",&u,&v); -Insert (U,v,1); theInsert (V,u,1); the } the while(BFS ()) the while(Ans=dinic (S),0x7fffffff)) maxlow+=ans; -printf"%d\n", Maxlow); the return 0; the}
C + + Path advanced--maximum flow (good vote)