真心大水题。。。不多说。

 #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基础题)的更多相关文章

  1. hdu-1879 继续畅通工程---确定部分边的MST

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1879 题目大意: 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的 ...

  2. hdu 1233 - 还是畅通工程(MST)

    还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  3. hdu 1863 - 畅通工程(MST)

    畅通工程 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  4. hdu1879 继续畅通工程

    http://acm.hdu.edu.cn/showproblem.php?pid=1879 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...

  5. 还是畅通工程(MST)

    还是畅通工程 Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  6. HDU1879 继续畅通工程 (并查集)

    继续畅通工程 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  7. HDU1879 继续畅通工程 2017-04-12 19:12 50人阅读 评论(0) 收藏

    继续畅通工程 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submis ...

  8. 【HDU1233】还是畅通工程(MST基础题)

    无坑,裸题.直接敲就恩那个AC. #include <iostream> #include <cstring> #include <cstdio> #include ...

  9. 【HDU1875】畅通工程再续(MST基础题)

    更改成实形数即可.第一次敲完直接交,CE了一次.晕. #include <iostream> #include <cstring> #include <cstdio> ...

随机推荐

  1. C++基础回顾2(函数, 指针和引用)

    接着回顾函数.指针和应用. 函数 1.多维数组作为形参时,第一维的大小可以省略(也可以不省略),但是其他维的大小必须指定.比如二维数组形参,int array[3][]不正确,int arry[][1 ...

  2. Thrift的安装和简单演示样例

    本文仅仅是简单的解说Thrift开源框架的安装和简单使用演示样例.对于具体的解说,后面在进行阐述. Thrift简述                                           ...

  3. Win7x64安装Oracle11201x64 解决PLSQL Developer无法找到oci问题

    http://blog.sina.com.cn/s/blog_4c7628c40101cf56.html http://blog.csdn.net/shenkxiao/article/details/ ...

  4. VS2015 添加DNX SDK

    第一次运行VS2015,添加第一个ASP.NET 5程序时会报一个错误“DNX SDK版本 “dnx-clr-win-x86.1.0.0-beta5”无法安装. 解决办法: 打开CMD :输入 @po ...

  5. alt和title的用法区别

    经常用到这两个属性,但是一直没有总结他们的区别.现在我对他们两个的用法做一下总结: 相同点:他们都会飘出一个小浮层,显示文本内容. 不同点: 1.alt只能是元素的属性,而title即可以是元素的属性 ...

  6. jquery颜色渐变

    http://files.cnblogs.com/handsomer/jquery.animate-colors-min.js

  7. AngularJs练习Demo10 ngInclude

    @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...

  8. 查看kafka的group.id

    kafka/config目录下的consumer.properties中可以看到

  9. OFBiz中根据店铺获取产品可用库存的方法

    1.[ProductStoreFacility]获得店铺绑定的仓库列表 2.遍历仓库,调用[getInventoryAvailableByFacility],传入[facilityId : facil ...

  10. 页面每次加载时重新获取css文件

    <script> (function(){ var version=''; var xmlhttp; // code for IE7+, Firefox, Chrome, Opera, S ...