-
열혈강호 - 11375Algorithm/BOJ 2020. 2. 24. 00:08123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263//11375 - 열혈강호#include <iostream>#include <vector>using namespace std;int N, M;vector<vector<bool>> adj;vector<int> aMatch, bMatch;vector<bool> visited;void init(){cin >> N >> M;adj = vector<vector<bool>>(N + 1, vector<bool>(M + 1, false));int n;int from;for(int to = 1; to<=N; ++to){cin >> n;for(int i = 0; i<n; ++i){cin >> from;adj[to][from] = true;}}}bool dfs(int here){if(visited[here]) return false;visited[here] = true;for(int there = 1; there<=M; ++there)if(adj[here][there])if(bMatch[there] == -1 || dfs(bMatch[there])){aMatch[here] = there;bMatch[there] = here;return true;}return false;}int bipartiteMatch(){aMatch = vector<int>(N+1, -1);bMatch = vector<int>(M+1, -1);int ret = 0;for(int i = 1; i<=N; ++i){visited = vector<bool>(N+1, false);if(dfs(i))++ret;}return ret;}int main(){ios_base::sync_with_stdio(0); cin.tie(0);init();cout << bipartiteMatch();}
cs https://www.acmicpc.net/problem/11375
11375번: 열혈강호
강호네 회사에는 직원이 N명이 있고, 해야할 일이 M개가 있다. 직원은 1번부터 N번까지 번호가 매겨져 있고, 일은 1번부터 M번까지 번호가 매겨져 있다. 각 직원은 한 개의 일만 할 수 있고, 각각의 일을 담당하는 사람은 1명이어야 한다. 각각의 직원이 할 수 있는 일의 목록이 주어졌을 때, M개의 일 중에서 최대 몇 개를 할 수 있는지 구하는 프로그램을 작성하시오.
www.acmicpc.net
열혈강호
이분매칭을 해결하기 위한 간략한 ford-fulkerson 알고리즘을 사용했습니다.
'Algorithm > BOJ' 카테고리의 다른 글
욕심쟁이 판다 - 1937 (0) 2020.02.25 최대 유량 - 6086 (0) 2020.02.25 발전소 - 1102 (0) 2020.02.23 외판원 순회 - 2098 (0) 2020.02.19 등산 - 1486 (0) 2020.02.18