Bounty Hunter II
Time Limit: 5000ms
Memory Limit: 262144KB
This problem will be judged on CodeForcesGym. Original ID: 100753B64-bit integer IO format: %I64d Java class name: (Any)
解题:最小路径覆盖
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 4010; 4 vector<int>g[maxn]; 5 int Link[maxn],n; 6 bool used[maxn]; 7 bool match(int u){ 8 for(int i = g[u].size()-1; i >= 0; --i){ 9 if(used[g[u][i]]) continue; 10 used[g[u][i]] = true; 11 if(Link[g[u][i]] == -1 || match(Link[g[u][i]])){ 12 Link[g[u][i]] = u; 13 return true; 14 } 15 } 16 return false; 17 } 18 int main(){ 19 int m; 20 while(~scanf("%d",&n)){ 21 for(int i = 0; i < maxn; ++i) g[i].clear(); 22 for(int i = 0; i < n; ++i){ 23 scanf("%d",&m); 24 for(int j = 0,v; j < m; ++j){ 25 scanf("%d",&v); 26 g[i].push_back(v + n); 27 } 28 } 29 memset(Link,-1,sizeof Link); 30 int ret = 0; 31 for(int i = 0; i < n; ++i){ 32 memset(used,false,sizeof used); 33 if(match(i)) ++ret; 34 } 35 printf("%d ",n - ret); 36 } 37 } 38 /* 39 4 40 1 1 41 1 2 42 0 43 1 1 44 45 6 46 0 47 1 2 48 2 4 5 49 1 2 50 0 51 0 52 53 5 54 1 4 55 1 4 56 1 4 57 1 4 58 0 59 */