Sicily 7766. Dark roads
来源:互联网 发布:华为matebook x知乎 编辑:程序博客网 时间:2024/06/05 04:26
7766. Dark roads
Constraints
Time Limit: 2 secs, Memory Limit: 256 MB
Description
Economic times these days are tough, even in Byteland. To reduce the operating costs, the government of Byteland has decided to optimize the road lighting. Till now every road was illuminated all night long, which costs 1 Bytelandian Dollar per meter and day. To save money, they decided to no longer illuminate every road, but to switch off the road lighting of some streets. To make sure that the inhabitants of Byteland still feel safe, they want to optimize the lighting in such a way, that after darkening some streets at night, there will still be at least one illuminated path from every junction in Byteland to every other junction.
What is the maximum daily amount of money the government of Byteland can save, without making their inhabitants feel unsafe?
Input
The input file contains several test cases. Each test case starts with two numbers mand n, the number of junctions in Byteland and the number of roads in Byteland, respectively. Input is terminated by m=n=0. Otherwise, 1 ≤ m ≤ 200000 and m-1 ≤ n ≤ 200000. Then follow n integer triples x, y, z specifying that there will be a bidirectional road between x and y with length z meters (0 ≤ x, y < m and x ≠ y). The graph specified by each test case is connected. The total length of all roads in each test case is less than 231.
Output
For each test case print one line containing the maximum daily amount the government can save.
Sample Input
7 110 1 70 3 51 2 81 3 91 4 72 4 53 4 153 5 64 5 84 6 95 6 110 0
Sample Output
51
Problem Source
2013年每周一赛第三场暨校赛模拟赛I
// Problem#: 7766// Submission#: 3380544// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <stdio.h>#include <iostream>#include <vector>#include <string>#include <stack>#include <iomanip>#include <algorithm>#include <queue>#include <functional>#include <map>#include <string.h>#include <math.h>using namespace std;const int MAX_N = 200005;const int MAX_E = 200005;struct edge { int u, v, cost;};int N, E;int par[MAX_N];edge ED[MAX_E];inline bool cmp(const edge & e1, const edge & e2) { return e1.cost < e2.cost;}void init() { for (int i = 0; i < N; i++) par[i] = i;}inline int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]);}inline void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; else par[x] = y;}int KRUSKAL() { sort(ED, ED + E, cmp); init(); int ans = 0; for (int i = 0; i < E; i++) { if (find(ED[i].u) != find(ED[i].v)) { unite(ED[i].u, ED[i].v); ans += ED[i].cost; } } return ans;}int main() { //std::ios::sync_with_stdio(false); char text[50]; while (1) { scanf("%d%d", &N, &E); gets(text); if (!N && !E) break; int sum = 0, j; for (int i = 0; i < E; i++) { gets(text); ED[i].u = ED[i].v = ED[i].cost = 0; for (j = 0; text[j] != ' '; j++) ED[i].u = ED[i].u * 10 + text[j] - '0'; j++; for (; text[j] != ' '; j++) ED[i].v = ED[i].v * 10 + text[j] - '0'; j++; for (; text[j] != '\0'; j++) ED[i].cost = ED[i].cost * 10 + text[j] - '0'; sum += ED[i].cost; } cout << sum - KRUSKAL() << endl; } return 0;}
- Sicily 7766. Dark roads
- SOJ 3427 Dark roads
- 3427: Dark roads
- Dark roads hdu2988 Kruskal
- Uva 11631 - Dark roads
- Uva-11631- Dark roads
- hdu 2988 Dark roads
- uva11631 - Dark roads
- UVa 11631 - Dark roads
- HDU2988 Dark roads【Kruskal】
- Dark roads--hdoj
- Dark roads 2988
- hdu 2988 Dark roads
- Dark roads(MST模板)
- hdu2988 Dark roads--Kruskal
- 杭电 2988 Dark roads
- HDU2988 Dark roads 【最小生成树Kruskal】
- HDU 2988 Dark roads 【最小生成树】
- memcache实现网站公用计数器
- 线程交替输出
- Sharding Scenario
- 四种方案解决ScrollView嵌套ListView问题
- jQuery 文本值改变的事件绑定
- Sicily 7766. Dark roads
- C++按一定格式输出到控制台,或者文件中
- c和c++的一些训练题(8)(打印心形)
- ORACLE函数大全
- 映射静态资源
- SAXParseException: cvc-id.1: There is no ID/IDREF binding for IDREF
- Java中字符输入输出流与字节输入输出流的区别
- xml和json互转的格式,结构
- Sicily 8543. Trees