HDOJ 1083 Hungarian实现
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDOJ 1083 Hungarian实现相关的知识,希望对你有一定的参考价值。
1 #include<cstdio> 2 #include<vector> 3 4 using namespace std; 5 6 #define N1 100 7 #define N2 300 8 9 int match[N2]; 10 vector<int> graph[N1]; 11 bool visit[N2]; 12 13 bool hungarian(int u){ 14 for (auto i = graph[u].begin(); i != graph[u].end(); i++) 15 if (!visit[*i]){ 16 visit[*i] = 1; 17 if (match[*i] == -1 || hungarian(match[*i])){ 18 match[*i] = u; 19 return true; 20 } 21 } 22 return false; 23 } 24 25 int main(){ 26 int m; 27 scanf("%d", &m); 28 for (int i = 0; i < m; i++){ 29 int p, n; 30 bool flag = 0; 31 scanf("%d %d", &p, &n); 32 for (int j = 0; j < p; j++){ 33 int num; 34 scanf("%d", &num); 35 graph[j].clear(); 36 for (int l = 0; l < num; l++){ 37 int student; 38 scanf("%d", &student); 39 graph[j].push_back(student - 1); 40 } 41 } 42 for (int j = 0; j < n; j++) 43 match[j] = -1; 44 for (int j = 0; j < p; j++){ 45 for (int l = 0; l < n; l++) 46 visit[l] = 0; 47 if (!hungarian(j)){ 48 flag = 1; 49 break; 50 } 51 } 52 if (flag) 53 printf("NO\n"); 54 else 55 printf("YES\n"); 56 } 57 return 0; 58 }
以上是关于HDOJ 1083 Hungarian实现的主要内容,如果未能解决你的问题,请参考以下文章
如何在 PySpark UDF 中使用边缘情况解决分配问题(如 Hungarian/linear_sum_assignment)
网络(最大)流初步+二分图初步 (浅谈EK,Dinic, Hungarian method:]
The Hungarian Abhorrence Principle