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.
  • 相关阅读:
    Redis的事务、锁及管理命令
    Redis消息队列
    Redis管理实战
    Redis入门部署及持久化介绍
    MySQL的存储引擎
    MHA高可用及读写分离
    jquery css hover
    SqlParameter 中 top 的使用
    Jquery 操作DropDownList 根据条件选中
    js 数值格式化函数
  • 原文地址:https://www.cnblogs.com/BLADEVIL/p/3464000.html
Copyright © 2011-2022 走看看