zoukankan      html  css  js  c++  java
  • poj1466

    求二分图的最大独立集 = x + y - maxmatch;

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    using namespace std;

    #define maxn 505

    int uN, vN;
    bool g[maxn][maxn];
    int xM[maxn], yM[maxn];
    bool chk[maxn];
    int n;

    void input()
    {
    int a, m;
    memset(g,
    0, sizeof(g));
    for (int i = 0; i < n; i++)
    {
    scanf(
    "%d", &a);
    scanf(
    ": (%d)", &m);
    for (int j = 0; j < m; j++)
    {
    scanf(
    "%d", &a);
    g[i][a]
    = true;
    }
    }
    }

    bool SearchPath(int u)
    {
    int v;
    for (v = 0; v < vN; v++)
    if (g[u][v] && !chk[v])
    {
    chk[v]
    = true;
    if (yM[v] == -1 || SearchPath(yM[v]))
    {
    yM[v]
    = u;
    xM[u]
    = v;
    return true;
    }
    }
    return false;
    }

    int MaxMatch()
    {
    int u, ret = 0;
    memset(xM,
    -1, sizeof(xM));
    memset(yM,
    -1, sizeof(yM));
    for (u = 0; u < uN; u++)
    if (xM[u] == -1)
    {
    memset(chk,
    false, sizeof(chk));
    if (SearchPath(u))
    ret
    ++;
    }
    return ret;
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    while (scanf("%d", &n) != EOF)
    {
    input();
    uN
    = n;
    vN
    = n;
    printf(
    "%d\n", n - MaxMatch() / 2);
    }
    return 0;
    }

  • 相关阅读:
    队列分类梳理
    停止线程
    Docker和Kubernetes
    Future、Callback、Promise
    Static、Final、static final
    线程池梳理
    TCP四次挥手
    http1.0、http1.x、http 2和https梳理
    重排序
    java内存模型梳理
  • 原文地址:https://www.cnblogs.com/rainydays/p/2085453.html
Copyright © 2011-2022 走看看