90分求调呜呜呜
查看原帖
90分求调呜呜呜
1159333
A_Little_BadBoy楼主2024/3/20 11:21
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N=505;
int m,n,c,in1,in2,res;
vector<int>all[N];
int root[N]={0};//表示右边的点和左边的哪一个点相连,0表示没有连接
int tmpfind[N]={0};//表示左边的点已经遍历到了哪一个位置

bool dfs(int tag)
{
    for(int i=tmpfind[tag];i<all[tag].size();i++)
    {
        tmpfind[tag]++;
        if(root[all[tag][i]]==0||dfs(root[all[tag][i]]))
        {
            root[all[tag][i]]=tag;
            return 1;
        }
    }
    return 0;
}

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m>>c;
    for(int i=0;i<c;i++)
    {
        cin>>in1>>in2;
        all[in1].push_back(in2);
    }
    for(int i=1;i<=n;i++)
    {
        res+=dfs(i);
    }
    cout<<res;
    return 0;
}

2024/3/20 11:21
加载中...