Hdoj 4687 Boke and Tsukkomi General graph Max match with Flower Tree + violence

Source: Internet
Author: User


General graph Max match with Flower Tree + violence:

Calculate the maximum matching C1 first

In enumerating each edge, remove the edges related to the two endpoints of the edge .... Then run Edmonds get match C2

Assuming C2+2==C1, the edge is again a maximum match.

Boke and TsukkomiTime limit:3000/3000 MS (java/others) Memory limit:102400/102400 K (java/others)
Total submission (s): 649 Accepted Submission (s): 202


Problem Descriptiona new season of Touhou M-1 Grand Prix is approaching. Girls in Gensokyo cannot wait for participating it. Before the registration, they has to decide which combination they is going to compete as. Every girl in Gensokyo is both a boke (Funny Girl) and a Tsukkomi (Straight girl). Every candidate combination is made up of the girls, a boke and a tsukkomi. A girl may belong to zero or more candidate combinations, but one can only register as a member of one formal combination. The host of Touhou M-1 Grand Prix hopes that as many formal combinations as possible can participate in this year. Under these constraints, some candidate combinations is actually redundant as it\ ' s impossible to register it as a formal One as long as the number of formal combinations have to be maximized. So they want-to-figure out these redundant combinations and stop considering about them.

Inputthere is multiple test cases. Process to the End of File.
The first line of all test case contains integers:1≤n≤40 and 1≤m≤ 123, where N is the number of girls in Gensokyo, and M is the number of candidate combinations. The following m lines is m candidate combinations, one by each line. Each combination was represented by and integers, the index of the Boke girl 1≤bi≤n and the index of the Tsukkomi girl 1≤ti≤n, where Bi! = Ti.
Outputfor each test case, output the number of redundant combinations in the first line. Then output the space-separated indexes of the redundant combinations on ascending order in the second line.
Sample Input
4 41 32 32 43 16 61 23 23 45 25 45 6

Sample Output
1232 4 5

Authorzejun Wu (Watashi)
Source

Field=problem&key=2013+multi-university+training+contest+9&source=1&searchmode=source "style=" color : rgb (26,92,200); Text-decoration:none ">2013 multi-university Training Contest 9

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Queue> #include <vector>using namespace std;const int maxn=50;vector<int> Ans;bool g[maxn][maxn],tg[ Maxn][maxn];int n,m;int match[maxn];int start,finish,newbase;int father[maxn],base[maxn];bool InQueue[maxn],InPath[ Maxn],inblossom[maxn];int count;queue<int> q;int findcommonancestor (int u,int v) {memset (InPath,false,sizeof (  Inpath));      while (true) {U=base[u];      Inpath[u]=true;      if (U==start) break;    U=father[match[u]];      } while (true) {v=base[v];      if (Inpath[v]) break;    V=FATHER[MATCH[V]]; } return v;}  void Resettrace (int u) {int V;      while (base[u]!=newbase) {v=match[u];      Inblossom[base[u]]=inblossom[base[v]]=true;      U=FATHER[V];    if (base[u]!=newbase) father[u]=v;  }}void blossomcontract (int u,int v) {newbase=findcommonancestor (u,v);  memset (inblossom,false,sizeof (Inblossom)); Resettrace (U); ReseTtrace (v);  if (base[u]!=newbase) father[u]=v;  if (base[v]!=newbase) father[v]=u;          for (int tu=1;tu<=n;tu++) {if (Inblossom[base[tu]]) {base[tu]=newbase; if (!              Inqueue[tu]) {Q.push (TU);            Inqueue[tu]=true;  }}}}void Findaugmentingpath () {memset (inqueue,false,sizeof (InQueue));  memset (father,0,sizeof (Father));  for (int i=1;i<=n;i++) base[i]=i;  while (!q.empty ()) Q.pop (); Q.push (Start);  Inqueue[start]=true;  finish=0;      while (!q.empty ()) {int U=q.front (); Q.pop ();      Inqueue[u]=false; for (int i=1;i<=n;i++) {if (i==u| |          G[u][i]==false) continue;          int v=i; if (base[u]!=base[v]&&match[u]!=v) {if (v==start| |                (match[v]>0&&father[match[v]]>0))              Blossomcontract (U,V);                  else if (father[v]==0) {father[v]=u;           if (match[v]>0)         {Q.push (match[v]);                    Inqueue[match[v]]=true;                      } else {finish=v;                    return;  }}}}}}void Augmentpath () {int u,v,w;  U=finish;      while (u>0) {v=father[u];      W=MATCH[V];      Match[v]=u;      Match[u]=v;    U=w;  }}void Edmonds () {memset (match,0,sizeof (Match));          for (int u=1;u<=n;u++) {if (match[u]==0) {start=u;          Findaugmentingpath ();        if (finish>0) Augmentpath ();      }}}int Bian[200][2];int Main () {while (scanf ("%d%d", &n,&m)!=eof) {memset (g,0,sizeof (G));      memset (tg,0,sizeof (TG));      Ans.clear ();          for (int i=0;i<m;i++) {int u,v;          scanf ("%d%d", &u,&v);          Bian[i][0]=u;bian[i][1]=v;          G[u][v]=g[v][u]=1;        Tg[u][v]=tg[v][u]=1; } EDMOnds ();      count=0;      for (int i=1;i<=n;i++) if (match[i]) count++;          for (int i=0;i<m;i++) {int u=bian[i][0],v=bian[i][1];            Clear about u,v for (int j=1;j<=n;j++) {g[u][j]=g[j][u]=g[j][v]=g[v][j]=0;          } Edmonds ();          int c2=0;          for (int j=1;j<=n;j++) if (match[j]) c2++;          if (c2<count-2) ans.push_back (i+1); Recover for (int j=1;j<=n;j++) {g[u][j]=tg[u][j];              G[j][u]=tg[j][u]; G[V][J]=TG[V][J];            G[J][V]=TG[J][V];        }} int sz = Ans.size ();        printf ("%d\n", SZ);            for (int i=0;i<sz;i++) {printf ("%d", ans[i]);        if (i<sz-1) printf ("");    } printf ("\ n"); } return 0;}




Hdoj 4687 Boke and Tsukkomi General graph Max match with Flower Tree + violence

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.