zoukankan      html  css  js  c++  java
  • Courses HDU

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    const int MAXN = 2e5;
    int match[MAXN], st[MAXN];
    int n,m,p;
    int e[MAXN],ne[MAXN],idx,h[MAXN];
    void add(int a,int b)
    {
    	e[idx]=b;
    	ne[idx]=h[a];
    	h[a]=idx++; 
    }
    bool find(int x)
    {
        for (int i = h[x];i!=-1;i=ne[i])
        {
            int j = e[i];
            if (st[j])
                continue;
            st[j] = 1;
            if (match[j] == -1 || find(match[j]))
            {
                match[j] = x;
                return true;
            }
        }
        return false;
    }
    
    int Solve()
    {
        int cnt = 0;
        memset(match, -1, sizeof(match));
        for (int i = 1;i <= p;i++)
        {
            memset(st, 0, sizeof(st));
            if (find(i))
                cnt++;
        }
        return cnt;
    }
    
    int main()
    {
        int t;
        cin >> t;
        while (t--)
        {
        	idx=0;
        	memset(h,-1,sizeof h);
            cin >> p >> n;
            if (p > n)
            {
                cout << "NO" << endl;
                continue;
            }
            for (int i = 1;i <= p;i++)
            {
                int num, v;
                cin >> num;
                while (num--)
                {
                    cin >> v;
                    add(i,v);
                }
            }
            int cnt = Solve();
            if (cnt < p)
                cout << "NO" << endl;
            else
                cout << "YES" << endl;
        }
    
        return 0;
    }
    
  • 相关阅读:
    LeetCode --- Climbing Stairs
    LeetCode --- Best Time to Buy and Sell Stock II
    LeedCode --- Best Time to Buy and Sell Stock
    git命令总结
    LeetCode --- Jump Game II
    Hdu 4497
    数据库lib7第4题创建存储过程
    Hdu 4496
    Hdu 4493
    快速排序
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12410180.html
Copyright © 2011-2022 走看看