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)
CodeForcesGym 100753B Bounty Hunter II
解题:最小路径覆盖
 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

 

相关文章:

  • 2021-09-23
  • 2021-06-16
  • 2021-07-21
  • 2021-08-09
  • 2021-08-13
  • 2021-11-15
  • 2021-07-14
  • 2021-07-08
猜你喜欢
  • 2021-11-30
  • 2021-11-28
  • 2022-12-23
  • 2021-06-07
  • 2021-08-07
  • 2022-02-04
  • 2021-08-22
相关资源
相似解决方案