BZOJ-2768: [JLOI2010] Championship poll (super Bare min cut)

Source: Internet
Author: User

2768: [JLOI2010] Championship survey time limit:10 Sec Memory limit:128 MB Description's annual UEFA Champions League has entered the knockout stage. Chelsea, the Premier League powerhouse, has become the number one hit by the elimination of the defending champion Barcelona. Sina Sports recently conducted a large-scale survey at the Jilin Institute of Education, which is about whether Chelsea will win the European Championship this year. Sina Sports reporters from all departments to take a total of n students as participants, we gathered in a hall, express. Each participant will speak and articulate their views. There was a perception in the minds of the participants, such as Firedancer that Chelsea could not win the championship, and Waterdancer that Chelsea must be. But because Waterdancer is a good friend of Firedancer, he may firedancer to support Chelsea in his speech in order to accommodate his good friends. This means that each participant speaks in a way that is not necessarily what the mind thinks. Now tell you all the thoughts and friends of the participants network, I hope you can arrange for each person's speech content, so that the total number of people who do not want to speak with the position of different friends (right) the total and minimum. Input first line two integers n and M, where N (2≤n≤300) represents the total number of participants, M (0≤m≤n (n-1)/2) represents the total logarithm of a friend. The second line is n integers, either 0 or 1. If the value of the I integer is 0, it means that I personally believe that Chelsea will not win the championship, if it is 1, that he believes Chelsea will be the first. The following m lines are two different integers per line, I and J (1≤i, j≤n) denote I and J are friends. Note that no pair of friends will appear repeatedly in the input. A friend relationship is two-way and does not pass. Output has only one integer, which is the smallest and. Sample INPUT3 3
1 0 0
1 2
1 3
2 3
Sample Output1hint

The best arrangement is for everyone to say that Chelsea will not win the championship. Not a pair of friends in the same position, only the 1th person he said his own words.

Minimal cut does not explain.

/************************************************************** problem:2768 USER:WINMT language:c++ Result : Accepted time:32 ms memory:3064 kb****************************************************************/#include <io stream> #include <fstream> #include <cstdio> #include <algorithm> #include <string> #include <vector> #include <queue> #include <deque> #include <utility> #include <map> #include < set> #include <cmath> #include <cstdlib> #include <ctime> #include <functional> #include < sstream> #include <cstring> #include <bitset> #include <stack>using namespace std; int n,m,s,t,cnt=1,x,y,z;struct sdt{int cap,flow,u,v;} E[90305];int Nxt[90305],fir[305],d[305],par[305],num[305],cur[305];bool vis[305];    int read () {int X=0;char c=getchar (); while (c<48| |    c>57) C=getchar ();    while (c>47&&c<58) X*=10,x+=c-48,c=getchar (); return x;} void Add (int u,int v,int cp,int FL) {E[++CNT].U=U;E[CNT].V=V;E[CNT].CAP=CP;E[CNT].FLOW=FL; nxt[cnt]=fir[u];fir[u]=cnt;}    void BFs () {//memset (vis,0,sizeof (VIS));    Memset (d,0,sizeof (d));    queue<int>q;    d[t]=0;    Vis[t]=1;    Q.push (t);        while (!q.empty ()) {int K=q.front ();        Q.pop (); for (int i=fir[k];i;i=nxt[i]) {if (!vis[e[i].v] && e[i].cap==0) {vis[e                [I].v]=1;                d[e[i].v]=d[k]+1;            Q.push (E[I].V);    }}}} int agument () {int p=t;    int ans=2147483647;        while (p!=s) {ans=min (ans,e[par[p]].cap-e[par[p]].flow);    p=e[par[p]].u;    } p=t;        while (p!=s) {E[par[p]].flow+=ans;        E[par[p]^1].flow-=ans;    p=e[par[p]].u; } return ans;    int Isap () {//memset (num,0,sizeof (num));    int flow=0;        for (int i=1;i<=t;i++) {num[d[i]]++;    Cur[i]=fir[i];    } int p=s;   while (d[s]<t) {if (p==t) {         Flow+=agument ();        P=s;        } bool ok=0;                  for (int i=cur[p];i;i=nxt[i]) {if (E[i].cap>e[i].flow && d[p]==d[e[i].v]+1) {                  ok=1;                  Par[e[i].v]=i;                  Cur[p]=i;                  P=E[I].V;              Break            }} if (!ok) {int mn=t-1;            for (int i=fir[p];i;i=nxt[i]) {if (E[i].cap>e[i].flow) mn=min (MN,D[E[I].V]);            } if (--num[d[p]]==0) break;            num[d[p]=mn+1]++;            CUR[P]=FIR[P];        if (p!=s) p=e[par[p]].u; }} return flow;}    int main () {n=read (); M=read ();    memset (nxt,0,sizeof (NXT));    memset (fir,0,sizeof (FIR));    S=1;    t=n+2;        for (int i=1;i<=n;i++) {z=read ();            if (z) {Add (s,i+1,1,0);        Add (i+1,s,0,0);            } else {Add (i+1,t,1,0); Add (t,i+1,1,0);        }} for (int i=1;i<=m;i++) {x=read (); Y=read ();        Add (1+x,1+y,1,0);    Add (y+1,x+1,1,0);    } BFS ();    printf ("%d\n", ISAP ()); return 0;}

  

BZOJ-2768: [JLOI2010] Championship poll (super Bare min cut)

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.