swust.oj.1075
来源:互联网 发布:python3防止sql注入 编辑:程序博客网 时间:2024/06/10 15:57
唉,看错了,写成了克鲁斯卡尔算法,尴尬
#include<stdio.h>#include<algorithm>#include<math.h>#include<string.h>#include<iostream>using namespace std;int b[20];struct node{char x, y;int date;}a[100];void init(){for (int i = 0; i < 20; i++){b[i] = i;}}bool cmp(node x, node y){if (x.date < y.date)return true;return false;}int find(int x){if (b[x] == x)return x;return b[x] = find(b[x]);}int main(){int n, m;while (cin >> n>>m){char ch[20];cin >> ch;init();for (int i = 0; i < m; i++){cin >> a[i].x >> a[i].y >> a[i].date;}sort(a, a + m, cmp);int k = 0;for (int i = 0; i < m; i++){if (k == n - 1)break;int x, y;for (int j = 0; j < n; j++){if (a[i].x == ch[j])x = j + 1;if (a[i].y == ch[j])y = j + 1;}if (find(x) != find(y)){cout << "(" << a[i].x << "," << a[i].y << ")";k++;b[find(x)] = b[find(y)];}}}return 0;}
0 0
- swust.oj.1075
- swust.oj.1075
- SWUST OJ 1025
- SWUST OJ 1137 STICKS
- SWUST OJ 1804 二进制
- swust OJ 1515
- swust OJ 1619 中位数
- SWUST OJ 2285
- swust.oj 0259
- swust.oj 0964
- swust.oj,0541
- swust.oj.319
- swust.oj.1013
- swust.oj.1015
- swust.oj.1072
- swust.oj.1076
- swust.oj.303
- swust oj 2620
- 第五届蓝桥杯java程序设计 c组决赛试题 年龄巧合
- CJOJ 1217 【HAOI2005】路由选择问题
- Codeforces Round #408 (Div. 2) A.Buying A House【模拟】水题~
- UICollectionView拾遗
- 数据结构课下复习1
- swust.oj.1075
- 飞翔nyoj195
- Lightoj1111——Best Picnic Ever(dfs)
- linux动态库及静态库的制作和makefile的简单编写
- [LintCode]Maximum Subarray III
- Android 唯一设备号生成方案
- 机器学习中各种距离
- 事件的绑定与解绑
- JNI学习积累之一 ---- 常用函数大全