1 条题解

  • 0
    @ 2017-09-07 21:29:32

    网络流最大匹配dfs求增广路裸的代码

    include <iostream>

    include <cstdio>

    include <cstring>

    using namespace std;
    int head[10202],match[10202];
    bool used[10202];
    int x,y;
    int V,k;
    int inde,n,m;
    struct path{
    int to,next;
    }edge[40002];
    void add(int x,int y){
    edge[++inde].to = y;
    edge[inde].next = head[x];
    head[x] = inde;
    }
    bool dfs(int u){
    used[u] = true;
    for(int i = head[u];i;i = edge[i].next){
    int v = edge[i].to,w = match[v];
    if(w < 0 || !used[w] && dfs(w)){
    match[u] = v;
    match[v] = u;
    return true;
    }
    }
    return false;
    }
    int er(){
    V = n * 2;
    int ans = 0;
    memset(match,-1,sizeof(match));
    for(int v = 1;v <= V;v++){
    if(match[v] < 0){
    memset(used,0,sizeof(used));
    if(dfs(v)){
    ans++;
    }
    }
    }
    return ans;
    }
    int main(){
    scanf("%d %d",&n,&k);
    for(int i = 1;i <= k;i++){
    scanf("%d %d",&x,&y);
    add(x, n + y);
    }
    printf("%d\n",er() * 13);
    }

  • 1

信息

难度
4
分类
网络流二分图二分图匹配 点击显示
标签
递交数
8
已通过
3
通过率
38%
上传者