标签:des style blog http color os io java ar
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3767 Accepted Submission(s): 1800
1 #include<cstdio> 2 #include<cstring> 3 #include<vector> 4 using namespace std; 5 const int maxn=301; 6 vector<int>mat[maxn]; 7 int judge[maxn]; 8 bool vis[maxn]; 9 bool skm(int x){ 10 vector<int>::iterator it; 11 for(it=mat[x].begin();it<mat[x].end();it++) 12 { 13 if(!vis[*it]) 14 { 15 vis[*it]=1; 16 if(judge[*it]==0||skm(judge[*it])) 17 { 18 judge[*it]=x; 19 return 1; 20 } 21 } 22 } 23 return 0; 24 } 25 26 int main() 27 { 28 int cas,n,m,t,a,i; 29 scanf("%d",&cas); 30 while(cas--) 31 { 32 scanf("%d%d",&n,&m); 33 memset(judge,0,sizeof(int)*(m+2)); 34 for( i=1;i<=n;i++) 35 { 36 mat[i].clear(); 37 scanf("%d",&t); 38 while(t--){ 39 scanf("%d",&a); 40 mat[i].push_back(a); 41 } 42 } 43 for(i=1;i<=n;i++){ 44 memset(vis,0,sizeof(bool)*(m+2)); 45 if(!skm(i))break; 46 } 47 if(i>n) printf("YES\n"); 48 else printf("NO\n"); 49 } 50 return 0; 51 }
采用邻接矩阵做:
1 #include<cstdio> 2 #include<cstring> 3 #include<vector> 4 #include<cstdlib> 5 #include<iostream> 6 using namespace std; 7 const int maxn=505; 8 bool mat[maxn][maxn]; 9 int judge[maxn]; 10 bool vis[maxn]; 11 int n,m; 12 bool skm(int x){ 13 for(int i=1;i<=m;i++) 14 { 15 if(!vis[i]&&mat[x][i]) 16 { 17 vis[i]=1; 18 if(judge[i]==0||skm(judge[i])) 19 { 20 judge[i]=x; 21 return 1; 22 } 23 } 24 } 25 return 0; 26 } 27 int main() 28 { 29 int cas,t,a,i; 30 //freopen("test.in","r",stdin); 31 scanf("%d",&cas); 32 while(cas--) 33 { 34 scanf("%d%d",&n,&m); 35 memset(judge,0,sizeof(judge)); 36 memset(mat,0,sizeof(mat)); 37 for( i=1;i<=n;i++) 38 { 39 scanf("%d",&t); 40 while(t--) 41 { 42 scanf("%d",&a); 43 mat[i][a]=1; 44 } 45 } 46 for(i=1;i<=n;i++){ 47 memset(vis,0,sizeof(vis)); 48 if(!skm(i))break; 49 } 50 if(i>n) 51 printf("YES\n"); 52 else 53 printf("NO\n"); 54 } 55 return 0; 56 }
标签:des style blog http color os io java ar
原文地址:http://www.cnblogs.com/gongxijun/p/3964299.html