【HDU1879】继续畅通工程(MST基础题)
真心大水题。。。不多说。
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <numeric> #define typec int
using namespace std; const typec inf = 0xffff;
const int V = ;
int vis[V];
typec lowc[V], Map[V][V]; typec prim (typec cost[][V], int n) {
int i, j, p;
typec minc, res = ;
memset(vis, , sizeof(vis));
vis[] = ;
for (i = ; i < n; ++ i) lowc[i] = cost[][i];
for (i = ; i < n; ++ i) {
minc = inf;
p = -;
for (j = ; j < n; ++ j) {
if ( == vis[j] && minc > lowc[j]) {
minc = lowc[j];
p = j;
}
}
if (inf == minc) return -;
res += minc;
vis[p] = ;
for (j = ; j < n; ++ j) {
if ( == vis[j] && lowc[j] > cost[p][j]) {
lowc[j] = cost[p][j];
}
}
}
return res;
} int main () {
int n;
while (~scanf("%d", &n)) {
if (!n) break;
for (int i = ; i < V; ++i) {
for (int j = ; j < V; ++ j) {
if (i == j) Map[i][j] = ;
else Map[i][j] = inf;
}
} for (int i = ; i < n * (n - ) / ; ++i) {
int x, y, w, ok;
scanf("%d%d%d%d", &x, &y, &w, &ok);
if (!ok) {
Map[x - ][y - ] = Map[y - ][x - ] = min(Map[x][y], w);
} else {
Map[x - ][y - ] = Map[y - ][x - ] = ;
}
} cout << prim(Map, n) << endl;
}
return ;
}
【HDU1879】继续畅通工程(MST基础题)的更多相关文章
- hdu-1879 继续畅通工程---确定部分边的MST
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1879 题目大意: 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的 ...
- hdu 1233 - 还是畅通工程(MST)
还是畅通工程 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 1863 - 畅通工程(MST)
畅通工程 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu1879 继续畅通工程
http://acm.hdu.edu.cn/showproblem.php?pid=1879 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...
- 还是畅通工程(MST)
还是畅通工程 Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- HDU1879 继续畅通工程 (并查集)
继续畅通工程 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDU1879 继续畅通工程 2017-04-12 19:12 50人阅读 评论(0) 收藏
继续畅通工程 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submis ...
- 【HDU1233】还是畅通工程(MST基础题)
无坑,裸题.直接敲就恩那个AC. #include <iostream> #include <cstring> #include <cstdio> #include ...
- 【HDU1875】畅通工程再续(MST基础题)
更改成实形数即可.第一次敲完直接交,CE了一次.晕. #include <iostream> #include <cstring> #include <cstdio> ...
随机推荐
- javascript笔记2之数据类型
/* var box; alert(typeof box); //box是Undefined类型,值是undefined,类型返回的字符串是undefined var box = true; aler ...
- 基于PCA和SVM的人脸识别系统-error修改
------------------------------------------------- Undefined function or variable 'W'. Error in class ...
- first day for new job
第一天上班,做个总结. 总得来说,感觉非常不错,一个结论~保持头脑清醒,好好加油. 今天主要办一些入职手续,拿到了代码,后面几天主要就是熟悉应用的功能.源代码.想好好制定个计划,定日目标. 1.功能结 ...
- [Javascript] Regex: '$`', '$&', '$''
var input = "foobar"; var result = input.replace('bar', '$`'); // $`: replace 'bar' with e ...
- linux服务器加入windows域时报错Ticket expired
[root@rusky]# net ads join -U administrator Enter administrator's password: kinit succeeded but ads_ ...
- 关闭程序 提示 C#
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { DialogResult dr = MessageBox ...
- 掌握jQuery插件开发,这篇文章就够了
---恢复内容开始--- 在实际开发工作中,总会碰到像滚动,分页,日历等展示效果的业务需求,对于接触过jQuery以及数据jQuery使用的人来说,首先想到的肯定是寻找现有的jQuery插件来满足形影 ...
- 不安装开发环境,查看logcat日志
#公司的测试终于想到要看 android 的日志.安装开发环境太麻烦了,这里有个简单的办法. 我把\sdk\platform-tools目录中,文件名以"adb"开头的三个文件打包 ...
- vim搜索后跳到下(上)一个
搜索高亮后, 跳到下一个:小写n 上一个:大写N
- C#读取USB的一些相关信息
在USB\VID_05A9&PID_2800\5&1BFE1C47&0&8里面,USB代表设备类型,5&1BFE1C47&0&8代表设备连接位置 ...