2坑,3次WA。

1.判断重边取小。2.自边舍去。

(个人因为vis数组忘记初始化,WA了3次,晕死!!)

 #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <numeric> #define typec int
using namespace std; const int V = ;
const typec inf = 0xffff;
int vis[V];
typec lowc[V];
int 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, road_n;
int cur = ;
while (cin >> n >> road_n) {
/*if (cur ++ != 0) {
cout << endl;
}*/
for (int i = ; i < n; ++ i) {
for (int j = ; j < n; ++ j) {
if (i == j) Map[i][j] = ;
else {
Map[i][j] = inf;
}
}
} for (int i = ; i < road_n; ++ i) {
int x, y, c;
scanf("%d%d%d", &x, &y, &c);
if (x == y) {
continue;
}
Map[x][y] = Map[y][x] = min(Map[x][y], c);
} int ans = prim (Map, n); if (ans == -) {
cout << "impossible" << endl << endl;
} else {
cout << ans << endl << endl;
}
}
return ;
}

【HDU2122】Ice_cream’s world III(MST基础题)的更多相关文章

  1. 【HDU1162】Eddy's picture(MST基础题)

    很基础的点坐标MST,一不留神就AC了, - - !! #include <iostream> #include <cstring> #include <cstdlib& ...

  2. 【HDU1301】Jungle Roads(MST基础题)

    爽爆.史上个人最快MST的记录7分40s..一次A. #include <iostream> #include <cstring> #include <cstdlib&g ...

  3. 【HDU1879】继续畅通工程(MST基础题)

    真心大水题...不多说. #include <iostream> #include <cstring> #include <cstdlib> #include &l ...

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

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

  5. 【HDU1102】Constructing Roads(MST基础题)

    最小生成树水题.prim一次AC #include <iostream> #include <cstring> #include <cstdlib> #includ ...

  6. 【HDU3371】Connect the Cities(MST基础题)

    注意输入的数据分别是做什么的就好.还有,以下代码用C++交可以过,而且是500+ms,但是用g++就会TLE,很奇怪. #include <iostream> #include <c ...

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

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

  8. Java底层基础题

    一.Java底层基础题 1.SpringMVC的原理以及返回数据如何渲染到jsp/html上? 答:Spring MVC的核心就是DispatcherServlet , 一个请求经过Dispatche ...

  9. HDU 2122 Ice_cream’s world III【最小生成树】

    解题思路:基础的最小生成树反思:不明白为什么i从1开始取,就一直WA,难道是因为村庄的编号是从0开始的吗 Ice_cream’s world III Time Limit: 3000/1000 MS ...

随机推荐

  1. openStack kilo 手动Manual部署随笔记录

    一 ,基于neutron网络资源主机(控制节点,网络节点,计算节点)网络规划配置 1, controller.cc 节点 网络配置截图

  2. 基于控制权限和登录验证跳转的django登录界面的实现

    django框架提供了出去登录和退出系统的login和logout的视图函数,本实现中使用系统自带的是视图函数.需要在settings.py,urls.py,views.py和模板文件等几个方面进行考 ...

  3. Sftp和ftp 差别、工作原理等(汇总ing)

    Sftp和ftp over ssh2的差别 近期使用SecureFx,涉及了两个不同的安全文件传输协议: -sftp -ftp over SSH2 这两种协议是不同的.sftp是ssh内含的协议,仅仅 ...

  4. 解决 Google 重定向,体验 Google 本味

    想要体验原汁原味的 Google(google.com),下面的方案是我用过的较方便的方案. 欢迎更正及补充 Chrome 扩展 Chrone 商店有一款禁止重定向的扩展 NoCountryRedir ...

  5. Android 编程下 Activity 的创建和应用退出时的销毁

    为了确保对应用中 Activity 的创建和销毁状态进行控制,所以就需要一个全局的变量来记录和销毁这些 Activity.这里的大概思路是写一个类继承 Application,并使获取该 Applic ...

  6. css_day7

  7. UIWindow in iOS

    这篇文章,我将分享对UIWindow我所知道的东西. keyWindow 一个应用能够有许多UIWindow,“The key window”是其中一个,被设计用来接受键盘和其他与点击无关的事件.一个 ...

  8. IO中手机旋转事件的传递

    UIApplication -> delegate -> widnow -> rootViewController

  9. Javascript进阶篇——(DOM—节点---属性、访问节点)—笔记整理

    节点属性在文档对象模型 (DOM) 中,每个节点都是一个对象.DOM 节点有三个重要的属性 : 1. nodeName : 节点的名称 2. nodeValue :节点的值 3. nodeType : ...

  10. EF中的连接字符串

    映射视图是每个实体集和关联的映射中指定的可转换的可执行表示. 包括两部分: 查询视图 表示从数据库架构转到概念架构所需的规范装换 更新视图 表示从概念模型转到数据库架构所需的规范转换 如果应用程序仅用 ...