Strategic GameTime Limit:10000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Sample Input
4 0:(1) 1 1:(2) 2 3 2:(0) 3:(0) 5 3:(3) 1 4 2 1:(1) 0 2:(0) 0:(0) 4:(0)
Sample Output
1 2
非常裸的最少点覆盖问题,宇宙中的生物都知道,最少点覆盖等于二分图最大匹配除以2.。。。
所以就是一道二分图最大匹配的问题,这题就是输入看起来有点麻烦,其它倒没什么,注意一下点的数量较多,就不要用邻接矩阵啦。
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; const int MAXN=5010; const int MAXM=50010; struct Edge { int to,next; } edge[MAXM]; int head[MAXN],tol; void init() { tol=0; memset(head,-1,sizeof(head)); } void addedge(int u,int v) { edge[tol].to=v; edge[tol].next=head[u]; head[u]=tol++; } int linker[MAXN]; bool used[MAXM]; int uN; bool dfs(int u) { for(int i=head[u]; i!=-1; i=edge[i].next) { int v=edge[i].to; if(!used[v]) { used[v]=true; if(linker[v]==-1||dfs(linker[v])) { linker[v]=u; return true; } } } return false; } int hungary() { int res=0; memset(linker,-1,sizeof(linker)); for(int u=0; u<uN; u++) { memset(used,false,sizeof(used)); if(dfs(u)) res++; } return res; } void getdata(char *data,int &node,int &num) { int i; node=num=0; for(i=0; data[i]!=':'; i++) { //cout<<data[i]<<endl; node*=10; node+=data[i]-'0'; } for(i+=2; data[i]!=')'; i++) { num*=10; num+=data[i]-'0'; } } int main() { char data[100]; int node,num,to,i,j; while(~scanf("%d",&uN)) { init(); for(j=0; j<uN; j++) { scanf("%s",data); getdata(data,node,num); //printf("%d %d\n",node,num); for(i=0; i<num; i++) { scanf("%d",&to); addedge(node,to); addedge(to,node); } } int ans=hungary(); printf("%d\n",ans/2); } return 0; }