码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForcesGym 100753B Bounty Hunter II

时间:2015-10-05 20:41:44      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

Bounty Hunter II

Time Limit: 5000ms
Memory Limit: 262144KB
This problem will be judged on CodeForcesGym. Original ID: 100753B
64-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",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 */
View Code

 

CodeForcesGym 100753B Bounty Hunter II

标签:

原文地址:http://www.cnblogs.com/crackpotisback/p/4856159.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!