Bzoj2768: [jloi2010] Champion Survey

Source: Internet
Author: User
2768: [jloi2010] Champion survey time limit: 10 sec memory limit: 128 MB
Submit: 484 solved: 332
[Submit] [Status] Description the annual European soccer Champions League has entered the knockout stage. With the elimination of the defending champion basarona, Chelsea became the top player in the Premier League. Sina sports recently conducted a large-scale survey at Jilin Institute of Education on whether Chelsea can win the European championship this year. Sina sports reporter extracted a total of N students from each department as participants. They gathered and expressed their opinions. Each participant will give a speech and describe his views. The participants share their thoughts. For example, firedancer believes that Chelsea cannot win the championship, while waterdancer believes that Chelsea must win the championship. But because waterdancer is a good friend of firedancer, firedancer may support Chelsea in his speech to accommodate his friends. That is to say, the comments presented by each participant are not necessarily what they think. I hope you can arrange your thoughts and comments for the participants so that the total number of people who speak in violation of your intention is different from the number of people who speak in the speech. (Yes) the sum and minimum of the total number. The first line of input contains two integers n and m, where N (2 ≤ n ≤ 300) indicates the total number of participants, M (0 ≤ m ≤ n (n-1)/2) represents the total logarithm of a friend. N integers in the second line, either 0 or 1. If the value of the I-th integer is 0, it indicates that I personally think that Chelsea will not win the championship. If it is 1, it means that he thinks Chelsea will win the championship. There are two different integers in each row in the M line below. I and j (1 ≤ I, j ≤ n) indicate that I and j are friends. Note that no friend will repeat the input. Friend relationships are bidirectional and will not be transmitted. Output has only one integer, which is the smallest sum. Sample input3 3
1 0 0
1 2
1 3
2 3
Sample output1hint

The best thing is that all people say in their speeches that Chelsea won't win. In this way, there is no friend with a different stance. Only 1st people have said anything against him.

Source

Question:

Champion survey = goodwill Voting

For bidirectional edges with mutually exclusive connection capacity 1, if 0 is supported, connect from S to 1. If 1 is supported, connect from t to 1, find the maximum stream.

Considering that every friend in a different set will contribute 1 to the minimum cut, and the contribution to the minimum cut will also be 1 to those who have spoken in violation of their intention.

Code:

 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #include<string>12 #define inf 100000000013 #define maxn 50014 #define maxm 15000015 #define eps 1e-1016 #define ll long long17 #define pa pair<int,int>18 #define for0(i,n) for(int i=0;i<=(n);i++)19 #define for1(i,n) for(int i=1;i<=(n);i++)20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)22 using namespace std;23 inline int read()24 {25     int x=0,f=1;char ch=getchar();26     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}27     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}28     return x*f;29 }30 int  n,m,s,t,maxflow,tot=1,a[maxn],b[maxn],head[maxn],cur[maxn],h[maxn],q[maxn];31 struct edge{int go,next,v;}e[maxm];32 void ins(int x,int y,int z){e[++tot].go=y;e[tot].v=z;e[tot].next=head[x];head[x]=tot;}33 void insert(int x,int y,int z){ins(x,y,z);ins(y,x,0);}34 bool bfs()35 {36     for(int i=s;i<=t;i++)h[i]=-1;37     int l=0,r=1;q[1]=s;h[s]=0;38     while(l<r)39     {40         int x=q[++l];41         for(int i=head[x];i;i=e[i].next)42          if(e[i].v&&h[e[i].go]==-1)43          {44             h[e[i].go]=h[x]+1;q[++r]=e[i].go;45          }46     }47     return h[t]!=-1;48 }49 int dfs(int x,int f)50 {51     if(x==t) return f;52     int tmp,used=0;53     for(int i=head[x];i;i=e[i].next)54      if(e[i].v&&h[e[i].go]==h[x]+1)55     {56         tmp=dfs(e[i].go,min(e[i].v,f-used));57         e[i].v-=tmp;if(e[i].v)cur[x]=i;58         e[i^1].v+=tmp;used+=tmp;59         if(used==f)return f;       60     }61     if(!used) h[x]=-1;62     return used;63 }64 void dinic()65 {66     maxflow=0;67     while(bfs())68     {69         for (int i=s;i<=t;i++)cur[i]=head[i];maxflow+=dfs(s,inf);70     }71 }72 int main()73 {74     freopen("input.txt","r",stdin);75     freopen("output.txt","w",stdout);76     n=read();m=read();s=0;t=n+1;77     for1(i,n)78      {79          int x=read();80          if(x)insert(i,t,1);else insert(s,i,1);81      }82     for1(i,m)83      {84         int x=read(),y=read();85         insert(x,y,1);insert(y,x,1);86      }87     dinic();88     printf("%d\n",maxflow);     89     return 0;90 }
View code

 

Bzoj2768: [jloi2010] Champion Survey

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.