标签:
传送门:hdu2063过山车
#include <cstdio> #include <cstring> #include <string> #include <cmath> #include <iostream> #include <algorithm> #include <queue> #include <cstdlib> #include <stack> #include <vector> #include <set> #include <map> #define LL long long #define mod 100000000 #define inf 0x3f3f3f3f #define eps 1e-6 #define N 310 #define FILL(a,b) (memset(a,b,sizeof(a))) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define PII pair<int,int> using namespace std; int g[N][N],vis[N],match[N]; int n,m; int dfs(int u) { for(int i=1;i<=m;i++) if(g[u][i]&&!vis[i]) { vis[i]=1; if(match[i]==-1||dfs(match[i])) { match[i]=u; return 1; } } return 0; } int main() { int t,num,x; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); FILL(g,0);FILL(match,-1); for(int i=1;i<=n;i++) { scanf("%d",&num); while(num--) { scanf("%d",&x); g[i][x]=1; } } int sum=0; for(int i=1;i<=n;i++) { FILL(vis,0); if(dfs(i))sum++; } if(sum==n)puts("YES"); else puts("NO"); } }
传送门:hdu1083 courses
#include <cstdio> #include <cstring> #include <string> #include <cmath> #include <iostream> #include <algorithm> #include <queue> #include <cstdlib> #include <stack> #include <vector> #include <set> #include <map> #define LL long long #define mod 100000000 #define inf 0x3f3f3f3f #define eps 1e-6 #define N 510 #define FILL(a,b) (memset(a,b,sizeof(a))) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define PII pair<int,int> using namespace std; int g[N][N],vis[N],match[N]; int n,m; int dfs(int u) { for(int i=1;i<=m;i++) if(g[u][i]&&!vis[i]) { vis[i]=1; if(match[i]==-1||dfs(match[i])) { match[i]=u; return 1; } } return 0; } int main() { int k; while(scanf("%d",&k),k) { scanf("%d%d",&n,&m); FILL(g,0);FILL(match,-1); while(k--) { int u,v; scanf("%d%d",&u,&v); g[u][v]=1; } int ans=0; for(int i=1;i<=n;i++) { FILL(vis,0); if(dfs(i))ans++; } printf("%d\n",ans); } }
标签:
原文地址:http://www.cnblogs.com/lienus/p/4285052.html