Luo Gu P1640 [SCOI2010] continuous attack game (bipartite graph matching)

Portal

Or that problem, bipartite graph maximum matching problem can not be a bare title, we will examine your ability to build graphs.

This question is for example, to achieve "a property for each equipment selection," the purpose, assume that x has a, b two properties, we can from a, b x is connected to a directed edge.

Then we turn from 1-10001 determine whether the match is completed, assuming that if y is not completed, then from 1 to y-1 is the completion of a match attribute, the answer is y-1.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXN 1000010
using namespace std;
int n,vis[MAXN],net[MAXN];
int head[10010],nxt[MAXN*2],to[MAXN*2],tot,tim;

void read(int &X){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
    X=x*f;
}

void add(int u,int v){to[++tot]=v;nxt[tot]=head[u];head[u]=tot;}

bool match(int u){
    for(int i=head[u];i;i=nxt[i])
        if(vis[to[i]]<tim){
            vis[to[i]]=tim;
            if(!net[to[i]] || match(net[to[i]])){
                net[to[i]]=u;
                return true;
            }
        }
    return false;
}

int main(){
    read(n);
    for(int i=1,a,b;i<=n;i++){read(a);read(b);add(a,i);add(b,i);}
    for(int i=1;i<=10001;i++){
        Tim ++;                // time stamp in place vis initializing the array, enhance the efficiency of 
        IF (! {match (I)) 
            the printf ( " % D \ n- " , I- . 1 );
             return  0 ; 
        } 
    }     
    return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/BakaCirno/p/11701650.html