zoukankan      html  css  js  c++  java
  • bzoj 1191 匈牙利算法

    只需要做一遍匈牙利,只要有一个没法匹配上就break就行了

    /**************************************************************
        Problem: 1191
        User: BLADEVIL
        Language: Pascal
        Result: Accepted
        Time:12 ms
        Memory:256 kb
    ****************************************************************/
     
    //By BLADEVIL
    var
        flag                    :array[0..1010] of boolean;
        link                    :array[0..1010] of longint;
        n, m                    :longint;
        pre, other, last        :array[0..2020] of longint;
        l                       :longint;
        ans                     :longint;
         
    procedure connect(x,y:longint);
    begin
        inc(l);
        pre[l]:=last[x];
        last[x]:=l;
        other[l]:=y;
    end;
         
    procedure init;
    var
        i                       :longint;
        x, y                    :longint;
    begin
        read(n,m);
        for i:=1 to m do
        begin
            read(x,y);
            connect(i,x);
            connect(i,y);
        end;
    end;
     
    function find(x:longint):boolean;
    var
        i                       :longint;
        q, p                    :longint;
    begin
        q:=last[x];
        while q<>0 do
        begin
            p:=other[q];
            if not flag[p] then
            begin
                flag[p]:=true;
                if (link[p]=0) or (find(link[p])) then
                begin
                    link[p]:=x;
                    exit(true);
                end;
            end;
            q:=pre[q];
        end;
        exit(false);
    end;
     
    procedure main;
    var
        i                       :longint;
    begin
        ans:=0;
        for i:=1 to m do
        begin
            fillchar(flag,sizeof(flag),false);
            if find(i) then inc(ans) else break;
        end;
        writeln(ans);
    end;
     
    begin
        init;
        main;
    end.
  • 相关阅读:
    Android教程 -07 Activity的任务栈和启动模式
    ViewPager封装工具类: 轻松实现APP导航或APP中的广告栏
    hdu 5900 区间dp
    状压dp入门
    poj 3280
    hdu 4745 two Rabits
    食了智,过来水一发
    poj 2142 the Balance
    hdu 6188 Duizi and Shunzi
    hdu 6186 CS Course
  • 原文地址:https://www.cnblogs.com/BLADEVIL/p/3464000.html
Copyright © 2011-2022 走看看