POJ-1325 machine Schedule Binary graph matching minimum point coverage problem

Source: Internet
Author: User

POJ-1325

Test instructions

  There are two machines A, B, respectively, have n,m mode, initially in 0 mode, now has K task, each task requires a or B to adjust to the corresponding mode to complete. Ask at least how many times the machine, a, or number of modes to complete the task.

Ideas:

It is equivalent to finding the minimum vertex coverage of a binary graph in a binary graph consisting of N and M points (that is, the number of vertices required for each task). According to the Konig theorem, the minimum vertex coverage number of a binary graph is the maximum number of matches, note that this is the base 0, is the initial adjustment mode can complete the 0 mode of the task, so read into the time not to consider the side with 0.

#include <algorithm>#include<iterator>#include<iostream>#include<cstring>#include<cstdlib>#include<iomanip>#include<bitset>#include<cctype>#include<cstdio>#include<string>#include<vector>#include<cmath>#include<queue>#include<list>#include<map>#include<Set>using namespacestd;//#pragma GCC optimize (3)//#pragma COMMENT (linker, "/stack:102400000,102400000")//C + +#defineLson (L, Mid, RT << 1)#defineRson (mid + 1, R, RT << 1 | 1)#defineDebug (x) cerr << #x << "=" << x << "\ n";#definePB Push_back#definePQ Priority_queuetypedefLong Longll;typedef unsignedLong LongUll;typedef pair<ll, LL >Pll;typedef pair<int,int>Pii;typedef pair<int,pii>P3;//priority_queue<int> Q;//This is a big root heap Q//priority_queue<int,vector<int>,greater<int> >q;//This is a little Gan q#defineFi first#defineSe Second//#define Endl ' \ n '#defineOKC Ios::sync_with_stdio (false); Cin.tie (0)#defineFT (A,B,C) for (int a=b; A <= C;++a)//used to press the line#defineREP (I, J, K) for (int i = j; i < K; ++i)//Priority_queue<int, Vector<int>, greater<int> >que;Constll mos =0x7FFFFFFF;//2147483647Constll nMOS =0x80000000;//-2147483648Const intINF =0x3f3f3f3f;Constll INFF =0x3f3f3f3f3f3f3f3f;// -Const intMoD = 1e9+7;Const DoubleESP = 1e-8;Const DoublePi=acos (-1.0); template<typename t>inline T read (t&x) {x=0;intf=0;CharCh=GetChar ();  while(ch<'0'|| Ch>'9') f|= (ch=='-'), ch=GetChar ();  while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); returnx=f?-x:x;}//#define _DEBUG; //*//#ifdef _debugfreopen ("input","R", stdin);//freopen ("Output.txt", "w", stdout);#endif/*-----------------------Showtime----------------------*/            Const intMAXN = 1e5+9; structedge{intV,nx;            }E[MAXN]; intH[maxn],tot =0; voidAddedge (intUintv) {E[TOT].V=v; E[tot].nx=H[u]; H[u]= tot++; }            intMX[MAXN],MY[MAXN],VIS[MAXN]; BOOLDfsintx) {                 for(inti = h[x]; ~i; i =e[i].nx) {                    intv =e[i].v; if(vis[v]==0) {Vis[v]=1; if(mx[v]==-1||DFS (Mx[v])) {Mx[v]=x; MY[X]=v; return true; }                    }                }                return false; }intMain () {intn,m,k;  while(~SCANF ("%d", &n) &&N) {Tot=0; memset (H,-1,sizeof(h)); memset (MX,-1,sizeof(MX)); Memset (My,-1,sizeof(my)); scanf ("%d%d", &m, &k);  for(intI=1; i<=k; i++){                    intu,v,q; scanf ("%d%d%d", &q, &u, &v); if(u*v) Addedge (u,v); }                intAns =0;  for(intI=1; i<n; i++) {memset (Vis,0,sizeof(VIS)); if(Dfs (i)) ans++; } printf ("%d\n", ans); }                        return 0;}
POJ1325

  

POJ-1325 machine Schedule Binary graph matching minimum point coverage problem

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.