标签:ane possible code ast start microsoft bool cep 标记
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 22584 | Accepted: 8914 |
Description
Input
Output
Sample Input
2 3 3 3 1 2 3 2 1 2 1 1 3 3 2 1 3 2 1 3 1 1
Sample Output
YES NO
Source
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 using namespace std; 5 bool g[110][310]; 6 bool flag,visit[310]; 7 int match[310]; 8 int p,n; 9 bool dfs(int u){ 10 for(int i=1;i<=n;++i){ 11 if(g[u][i]&&!visit[i]){ 12 visit[i]=true; 13 if(match[i]==-1 || dfs(match[i])){ 14 match[i]=u; 15 return true; 16 } 17 } 18 } 19 return false; 20 } 21 int main() { 22 int i,j,k,t,v,ans; 23 scanf("%d",&t); 24 while(t--){ 25 scanf("%d %d", &p, &n); 26 for(i=1;i<=p;i++){ 27 for(j=1;j<=n;j++) 28 g[i][j]=false; 29 } 30 for(i=1;i<=n;i++) 31 match[i]=-1; 32 flag=true; 33 for(i=1;i<=p;i++){ 34 scanf("%d",&k); 35 if(k == 0) flag=false; 36 while(k--){ 37 scanf("%d",&v); 38 g[i][v]=true; 39 } 40 } 41 if(flag){ 42 ans=0; 43 for(i=1;i<=p;i++){ 44 memset(visit,false,sizeof(visit)); //清空上次搜索时的标记 45 if(dfs(i)) ans++; 46 } 47 if(ans == p)puts("YES"); 48 else puts("NO"); 49 } 50 else puts("NO"); 51 } 52 return 0; 53 }
标签:ane possible code ast start microsoft bool cep 标记
原文地址:http://www.cnblogs.com/suishiguang/p/6430029.html