hdu 1504最小点集覆盖
2012-08-15 15:34
246 查看
这题先用邻接矩阵打了试,TLE,改成邻接表,就过了。。
/* * hdu1054/win.cpp * Created on: 2012-8-14 * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <set> #include <map> #include <stack> #include <string> #include <vector> #include <deque> #include <list> #include <functional> #include <numeric> #include <cctype> using namespace std; const int MAXN = 1600; int N, mymatch[MAXN], temp[MAXN]; vector<int> mymap[MAXN]; bool visited[MAXN]; void init() { for(int i = 0; i < N; i++) { mymap[i].clear(); } } bool dfs(int k) { int t, I; for(int i = 0; i < (int)mymap[k].size(); i++) { I = mymap[k][i]; if(!visited[I]) { visited[I] = true; t = mymatch[I]; mymatch[I] = k; if(t == -1 || dfs(t)) { return true; } mymatch[I] = t; } } return false; } int hungary () { memset(mymatch, -1, sizeof(mymatch)); int ans = 0; for (int i = 0; i < N; i++) { memset(visited, false, sizeof(visited)); if (dfs(i)) { ans++; } } return ans; } bool buildgraph() { int t, k, a; if(scanf("%d", &N) == EOF) { return false; } init(); memset(temp, -1, sizeof(temp)); bool flag = false; for(int i = 0; i < N; i++) { scanf("%d:(%d)", &a, &k); if(!flag) { if(k > 0) { temp[a] = 0; flag = true; } } for(int j = 0; j < k; j++) { scanf("%d", &t); if(temp[a] == 0) { temp[t] = 1; mymap[a].push_back(t); }else{ temp[t] = 0; mymap[t].push_back(a); } } } return true; } int main() { #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); #endif while(buildgraph()) { printf("%d\n", hungary()); } return 0; }
相关文章推荐
- HDU 1150 二分图最小点集覆盖
- hdu National Treasures 二分图的最小点集覆盖
- hdu 2119最小点集覆盖
- hdu 1054 最小点集覆盖 || 树形dp
- HDU 2119 Matrix【二分图之最小点集覆盖】
- HDU1150 (最小点集覆盖)
- hdu 4160 Dolls--最小点集覆盖=V-二分图最大匹配
- hdu 1845 Jimmy’s Assignment 二分匹配最小点集覆盖
- hdu1150 Machine Schedule(最小点覆盖)
- HDU 4160 最小路径覆盖 = 顶点数 - 最大匹配数 二分匹配
- HDU 1150 Machine Schedule(最小点覆盖数 = 最大匹配数)
- HDU 1150 -- Machine Schedule (最小点覆盖)
- HDU 3991 最短路+最小路径覆盖
- hdu1350——Taxi Cab Scheme——————【最小路径覆盖、最大匹配转化】
- hdu 1054 树的最小点覆盖
- hdu-----(1151)Air Raid(最小覆盖路径)
- HDU 3861 The King’s Problem (强连通分量缩点+二分图匹配最小路径覆盖)
- HDU 1054 Strategic Game (最小顶点覆盖)
- HDU 4606 Occupy Cities (计算几何+最短路+最小路径覆盖)
- 二分图最大匹配的König定理-最小点集覆盖【Matrix67】