标签:
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5214 Accepted Submission(s): 2502
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<vector> 7 #define mem(x,y) memset(x,y,sizeof(x)) 8 using namespace std; 9 const int INF=0x3f3f3f3f; 10 const int MAXN=350; 11 vector<int>vec[MAXN]; 12 int usd[MAXN],vis[MAXN]; 13 bool dfs(int x){ 14 for(int i=0;i<vec[x].size();i++){ 15 int v=vec[x][i]; 16 if(!vis[v]){ 17 vis[v]=1; 18 if(!usd[v]||dfs(usd[v])){ 19 usd[v]=x;return true; 20 } 21 } 22 } 23 return false; 24 } 25 int main(){ 26 int T,P,N,t,a; 27 scanf("%d",&T); 28 while(T--){ 29 mem(usd,0); 30 mem(vis,0); 31 for(int i=0;i<MAXN;i++)vec[i].clear(); 32 scanf("%d%d",&P,&N); 33 for(int i=1;i<=P;i++){ 34 scanf("%d",&t); 35 while(t--){ 36 scanf("%d",&a); 37 vec[i].push_back(a); 38 } 39 } 40 int ans=0; 41 for(int i=1;i<=P;i++){ 42 mem(vis,0); 43 if(dfs(i))ans++; 44 } 45 if(ans==P)puts("YES");//应该是等于P的 46 else puts("NO"); 47 } 48 return 0; 49 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4957404.html