POJ 3723 Conscription 并查集 + Kruskal
来源:互联网 发布:刀具长度补偿怎么编程 编辑:程序博客网 时间:2024/06/07 06:08
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;#define MAX_N 20002#define MAX_E 50001struct edge{int u, v, cost;};int par[MAX_N];int Rank[MAX_N];edge es[MAX_E];int V, E;bool compare(const edge &e1, const edge &e2){return e1.cost<e2.cost;}void init(int N){for (int i = 0; i<N; i++){par[i] = i;Rank[i] = 0;}}int find(int x){if (par[x] == x)return x;elsereturn par[x]=find(par[x]);}void unite(int x, int y){x = find(x);y = find(y);if (x == y) return;if (Rank[x]>Rank[y])swap(x, y);par[x] = y;Rank[x]++;}bool same(int x, int y){x = find(x);y = find(y);return x == y;}int krus(){sort(es, es + E, compare);init(V);int ret = 0;for (int i = 0; i<E; i++){if (same(es[i].u, es[i].v) == false){ret += es[i].cost;unite(es[i].u, es[i].v);}}return ret;}int main(){int count;int N, M;scanf("%d", &count);for (int i = 0; i<count; i++){scanf("%d%d%d", &N, &M, &E);for (int j = 0; j<E; j++){int v, cost;scanf("%d%d%d", &es[j].u, &v, &cost);es[j].v = v + N;es[j].cost = -cost;}V = M + N;printf("%d\n", V * 10000 + krus());}return 0;}
0 0
- POJ 3723 Conscription 并查集 + Kruskal
- poj 3723 Conscription 并查集+Kruskal 求最小生成树
- POJ 3723 Conscription (求最大权森林,kruskal,并查集)
- poj 3723 Conscription (并查集)
- [POJ3723]Conscription[并查集][kruskal]
- Conscription(并查集+kruskal)
- POJ 3723 Conscription 克鲁斯卡尔+并查集
- POJ 3723 Conscription 最大生成树 + 并查集
- POJ 3723 Conscription(并查集+最小生成树)
- POJ 3723 Conscription (Kruskal并查集求最小生成树)
- POJ 3723 Conscription(Kruskal算法)
- POJ3723 Conscription 【并查集】
- POJ 1861 Network (Kruskal+并查集)
- poj 1287 kruskal 并查集
- kruskal+ 并查集
- Kruskal+并查集
- Kruskal + 并查集
- POJ 3723 Conscription (最大权森林 + Kruskal算法)
- ie下如何打开cmd
- error A2004: symbol type conflict
- 树莓派_GPIO引脚操作_wiringPi的安装与使用
- extjs grid renderer用法
- UITextField属性
- POJ 3723 Conscription 并查集 + Kruskal
- UITextView
- UIView属性
- ACdream Online Judge 1093
- JavaScript程序应该由桃园三结义组成
- 深入分析 Java I/O 的工作机制
- uva 111 - History Grading(LCS)
- 文本属性Attributes
- JDK安装及环境变量配置