Nyoj's 239-month-old problem: maximum matching of bipartite graphs

Source: Internet
Author: User

Question link: http://acm.nyist.net/JudgeOnline/problem.php? PID = 1, 239

 

Idea: maximum matching of a bipartite graph ~~~ Joining Table A through ~~

 

#include <iostream>#include <cstring>using namespace std;int num;int n,k;int s;struct node{    int u,v,w;    int next;}map[10010];int head[510];int match[510];int used[510];bool solve(int s){    for(int i = head[s]; i != -1; i = map[i].next)    {        if(used[map[i].v] == 0)        {            used[map[i].v] = 1;            if(match[map[i].v] == -1 || solve(match[map[i].v]) == true)            {                match[map[i].v] = s;                return true;            }        }    }    return false;}void add_edge(int u, int v, int w){    map[s].u = u;    map[s].v = v;    map[s].w = 1;    map[s].next = head[u];    head[u] = s++;} int main(){    cin>>num;        int a,b;    while(num--)    {        s = 0;        cin>>n>>k;                memset(head, -1, sizeof(head));        memset(map, 0, sizeof(map));        memset(match,-1,sizeof(match));        for(int i=1; i<=k; i++)        {            cin>>a>>b;            add_edge(a,b,1);         }                int res = 0;        for(int i=1; i<=n; i++)        {            memset(used, 0, sizeof(used));            if(solve(i))                res++;        }        cout<<res<<endl;    }    return 0;} 

 

Nyoj's 239-month-old problem: maximum matching of bipartite graphs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.