1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| #include <iostream> #include <cstring> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <cmath> #include <cstdio> #include <map>
using namespace std; #define mem(a, b) memset(a, b, sizeof(a)) #define PI acos(-1) #define DEBUG(a) cout << (a) << endl typedef long long ll; int dir8[8][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {-1, 1}, {-1, -1}, {1, -1}, {1, 1}}; int dir4[4][2] = {1, 0, 0, 1, -1, 0, 0, -1}; const int INF = 0x3f3f3f3fLL; const long long LLF = 0x3f3f3f3f3f3f3f3fLL; const int MAXn = 1e5 + 15; const int mod = 1e9 + 7;
int cnt,n,m,Next[400]; bool mapn[402][402],mark[400]; bool check(int x) { for (int i=1;i<=m;i++) if (mapn[x][i]&&(!mark[i])) { mark[i]=true; if (Next[i]==0check(Next[i])) { Next[i]=x; return true; } } return false; } int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) { int a; scanf("%d",&a); for (int j=1;j<=a;j++) { int b; scanf("%d",&b); mapn[i][b]=true; } } for (int i=1;i<=n;i++) { for (int j=1;j<=m;j++) mark[j]=false; if (check(i)) cnt++; } printf("%d\n",cnt); return 0; }
|