SHARE
    TWEET
    Vince14

    /<> 11377 (maximum bipartite matching multiple possible)

    Oct 28th, 2023
    126
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    C++ 1.47 KB | Source Code | 0 0
    1. #include <iostream>
    2. #include <string>
    3. #include <cstring>
    4. #include <algorithm>
    5. #include <cmath>
    6. #include <vector>
    7. #include <set>
    8. #include <map>
    9. #include <stack>
    10. #include <queue>
    11. #include <deque>
    12. #include <unordered_map>
    13. #include <numeric>
    14. #include <iomanip>
    15. using namespace std;
    16. #define pii pair<int , int>
    17. #define ll long long
    18. #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
    19. const long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1};
    20. const long long dl[2] = {1, -1};
    21. const long long MOD = 1000000007;
    22. const long long MAXN = 1005;
    23. int n, m, k, ans = 0;
    24. vector<int> v[MAXN];
    25. vector<bool> visited;
    26. vector<int> work;
    27. bool dfs(int cur){
    28. if(visited[cur]){
    29. return false;
    30. }
    31. visited[cur] = true;
    32. for(auto nxt : v[cur]){
    33. if(work[nxt] == -1 || dfs(work[nxt])){
    34. work[nxt] = cur;
    35. return true;
    36. }
    37. }
    38. return false;
    39. }
    40. int main() {
    41. FAST;
    42. cin >> n >> m >> k;
    43. for(int x, i = 0; i < n; i++){
    44. cin >> x;
    45. for(int y, j = 0; j < x; j++){
    46. cin >> y;
    47. y--;
    48. v[i].push_back(y);
    49. }
    50. }
    51. work.assign(m, -1);
    52. for(int i = 0; i < n; i++){
    53. visited.assign(n, false);
    54. if(dfs(i)){
    55. ans++;
    56. }
    57. }
    58. for(int i = 0; i < n && k > 0; i++){
    59. visited.assign(n, false);
    60. if(dfs(i)){
    61. ans++;
    62. k--;
    63. }
    64. }
    65. cout << ans << "\n";
    66. }
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /