标签:des style blog http color os java io strong
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5034 Accepted Submission(s): 2297
1 #include<cstring> 2 #include<cstdio> 3 #include<vector> 4 #include<iostream> 5 using namespace std; 6 const int maxn=1550; 7 vector<vector<int> >grid(maxn); 8 bool vis[maxn]; 9 int savx[maxn]; 10 int n; 11 int km(int x){ 12 vector<int>::iterator it; 13 for(it=grid[x].begin();it<grid[x].end();it++){ 14 if(!vis[*it]){ 15 vis[*it]=1; 16 if(savx[*it]==-1||km(savx[*it])){ 17 savx[*it]=x; 18 return 1; 19 } 20 } 21 } 22 return 0; 23 } 24 25 int main(){ 26 int ans=0; 27 int a,b,c; 28 int km(int ); 29 while(scanf("%d",&n)!=EOF){ 30 ans=0; 31 memset(savx,-1,sizeof(savx)); 32 for(int i=0;i<n;i++) 33 grid[i].clear(); 34 for(int i=0;i<n;i++){ 35 scanf("%d:(%d)",&a,&b); 36 for(int j=0;j<b;j++){ 37 scanf("%d",&c); 38 grid[a].push_back(c); 39 grid[c].push_back(a); 40 } 41 } 42 for(int i=0;i<n;i++){ 43 memset(vis,0,sizeof(vis)); 44 ans+=km(i); 45 } 46 printf("%d\n",ans/2); 47 } 48 return 0; 49 }
hdu---(1054)Strategic Game(最小覆盖边)
标签:des style blog http color os java io strong
原文地址:http://www.cnblogs.com/gongxijun/p/3937480.html