poj 2485 Highways
来源:互联网 发布:objective c 高级编程 编辑:程序博客网 时间:2024/05/18 06:16
#include <cstdio>#include <vector>#include <algorithm>using namespace std;#define N 1000int bing[N];struct coord{int x, y;int quan;};bool cmp(const coord a, const coord b){return a.quan < b.quan;}int search(int a){if (a == bing[a])return a;elsereturn bing[a] = search(bing[a]);}bool getin(int a, int b){int t1, t2;t1 = search(a);t2 = search(b);if (t1 != t2){bing[t1] = t2;return true;}return false;}int main(){int i;cin >> i;while (i--){int a, b, ge, quan;vector<coord> map;int sb;coord ak_47;int count = 0;scanf("%d", &ge);for (a = 1; a <= ge; a++){bing[a] = a;for (b = 1; b <= ge; b++){scanf("%d", &quan);if (quan != 0 && a > b){ak_47.quan = quan;ak_47.x = a;ak_47.y = b;map.push_back(ak_47);}}}sort(map.begin(), map.end(), cmp);for (int a = 0; a != map.size(); a++){//cout << map[a].quan << endl;if (getin(map[a].x, map[a].y)){count++;if (count == ge - 1)sb = map[a].quan;}}printf("%d\n", sb);//system("pause");}}
一道最小生成树的水题,很简单就能做出来。题意就是找出来最小生成树中的最大边,需要注意的是对边进行排序的时候注意不要排反了。
0 0
- poj poj 2485 Highways
- POJ 2485 Highways
- poj 2485 Highways
- POJ-2485 highways
- POJ 2485 Highways Kruskal
- poj 2485 Highways
- Poj 2485 Highways
- POJ 2485 Highways
- poj 2485 Highways
- poj 2485 Highways
- POJ 2485 Highways
- POJ 2485 Highways
- POJ 2485 Highways
- POJ 2485 Highways
- Poj 2485 Highways
- poj 2485 Highways
- poj 2485 highways
- POJ 2485 Highways
- JavaSe基础(23)-- 基本数据类型的包装类
- SecureCRT 8.0发布
- Android odex文件反编译
- 制作一个可以滑动操作的 Table View Cell
- 献给20----25岁正在奋斗的年轻人们
- poj 2485 Highways
- protocol buffer安装后使用出错
- 怎么样设计良好的API
- java web表单提交ajax参数封装方法
- TortoiseGit 使用教程
- K 近邻算法(KNN)与KD 树实现
- UVA 10048 A - Wormholes
- 携程Docker实践
- ios学习--正则表达式简介