Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10656 | Accepted: 4814 |
Description
Input
Output
Sample Input
5
1 1 1
2 1 1 2 2
1 2 2
2 3 2 3 3
1 3 3
Sample Output
4
Source
题目大意:
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define N 310 using namespace std; bool vis[N]; int n,m,x,y,t,ans,pre[N],map[N][N]; int read() { int x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘) f=-1; ch=getchar();} while(ch<=‘9‘&&ch>=‘0‘){x=x*10+ch-‘0‘; ch=getchar();} return x*f; } int find(int x) { for(int i=1;i<=m;i++) if(!vis[i]&&map[x][i]) { vis[i]=true; if(pre[i]==-1||find(pre[i])) { pre[i]=x; return 1; } } return 0; } int main() { while(~scanf("%d",&n)) { ans=0;m=7*12; memset(map,0,sizeof(map)); memset(pre,-1,sizeof(pre)); for(int i=1;i<=n;i++) { t=read(); while(t--) x=read(),y=read(),map[i][(x-1)*12+y]=1; } for(int i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(find(i)) ans++; } printf("%d\n",ans); } return 0; }
原文:http://www.cnblogs.com/z360/p/7105466.html