题意  一个城市原来有l个村庄 e1条道路  又添加了n个村庄 e2条道路  后来后销毁了m个村庄  与m相连的道路也销毁了  求使全部未销毁村庄相互连通最小花费  不能连通输出what a pity!

还是非常裸的最小生成树  把销毁掉的标记下  然后prim咯  结果是无穷大就是不能连通的

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 300;
int mat[N][N], des[N], d[N], ans, n, m; void prim()
{
memset(d, 0x3f, sizeof(d));
int s = 0; while(des[s]) ++s;
d[s] = -1;
int cur = s, next = n;
for(int k = 1; k < n - m; ++k)
{
for(int i = 0; i < n; ++i)
{
if(des[i] || d[i] < 0) continue;
d[i] = min(d[i], mat[cur][i]);
if(d[i] < d[next]) next = i;
}
ans += d[next], d[next] = -1, cur = next, next = n;
}
} int main()
{
int cas, l, e1, e2, a, b, c;
scanf("%d", &cas);
while(cas--)
{
memset(mat, 0x3f, sizeof(mat));
memset(des, 0, sizeof(des));
scanf("%d %d", &l, &e1);
for(int i = 0; i < e1; ++i)
{
scanf("%d%d%d", &a, &b, &c);
if(c < mat[a][b]) mat[a][b] = mat[b][a] = c;
} scanf("%d %d", &n, &e2);
for(int i = 0; i < e2; ++i)
{
scanf("%d%d%d", &a, &b, &c);
if(c < mat[a][b]) mat[a][b] = mat[b][a] = c;
} n = n + l;
scanf("%d", &m);
for(int i = 0; i < m; ++i)
{
scanf("%d", &a);
des[a] = 1;
} ans = 0; prim();
if(ans < d[n]) printf("%d\n", ans);
else printf("what a pity!\n");
}
return 0;
}

The plan of city rebuild

Problem Description
News comes!~City W will be rebuilt with the expectation to become a center city. There are some villages and roads in the city now, however. In order to make the city better, some new villages should be built and some old
ones should be destroyed. Then the officers have to make a new plan, now you , as the designer, have the task to judge if the plan is practical, which means there are roads(direct or indirect) between every two villages(of course the village has not be destroyed),
if the plan is available, please output the minimum cost, or output"what a pity!".
 
Input
Input contains an integer T in the first line, which means there are T cases, and then T lines follow.

Each case contains three parts. The first part contains two integers l(0<l<100), e1, representing the original number of villages and roads between villages(the range of village is from 0 to l-1), then follows e1 lines, each line contains three integers a,
b, c (0<=a, b<l, 0<=c<=1000), a, b indicating the village numbers and c indicating the road cost of village a and village b . The second part first contains an integer n(0<n<100), e2, representing the number of new villages and roads(the range of village is
from l to l+n-1), then follows e2 lines, each line contains three integers x, y, z (0<=x, y<l+n, 0<=z<=1000), x, y indicating the village numbers and z indicating the road cost of village x and village y. The third part contains an integer m(0<m<l+n), representing
the number of deserted villages, next line comes m integers, p1,p2,…,pm,(0<=p1,p2,…,pm<l+n) indicating the village number. 

Pay attention: if one village is deserted, the roads connected are deserted, too.
 
Output
For each test case, If all villages can connect with each other(direct or indirect), output the minimum cost, or output "what a pity!".
 
Sample Input
2
4 5
0 1 10
0 2 20
2 3 40
1 3 10
1 2 70
1 1
4 1 60
2
2 3
3 3
0 1 20
2 1 40
2 0 70
2 3
0 3 10
1 4 90
2 4 100
0
 
Sample Output
70
160
 

HDU 3080 The plan of city rebuild(除点最小生成树)的更多相关文章

  1. HDU 3080 The plan of city rebuild(prim和kruskal)

    The plan of city rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  2. 2015 Multi-University Training Contest 1 hdu 5290 Bombing plan

    Bombing plan Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  3. HDU 3757 Evacuation Plan DP

    跟 UVa 1474 - Evacuation Plan 一个题,但是在杭电上能交过,在UVa上交不过……不知道哪里有问题…… 将施工队位置和避难所位置排序. dp[i][j] 代表前 i 个避难所收 ...

  4. hdu 5290 Bombing plan

    http://acm.hdu.edu.cn/showproblem.php?pid=5290 题意: 一棵树,每个点有一个权值wi,选择点i即可破坏所有距离点i<=wi的点,问破坏所有点 最少需 ...

  5. HDU 4671 Backup Plan (2013多校7 1006题 构造)

    Backup Plan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  6. HDU 2103 Family Plan

    题目HDU 2103:http://acm.hdu.edu.cn/showproblem.php?pid=2103 Problem Description As far as we known,the ...

  7. hdu 4671 Backup Plan(签到题)

    错成那样,还以为是卡时间卡精度的变态题,结果就那么ac了= = 悔死我了 题意就不概述了,只要处理前两列即可.其中第一列顺序直接扫一遍,第二列要先处理较少的那几种.我是接着第一列用 head[] 继续 ...

  8. HDU 4671 Backup Plan 构造

    负载是否平衡只与前两列有关,剩下的只要与前两列不重复就随便放. 第一列我们按1-n这样循环放,第二列每次找个数最少的那个服务器放. #include <cstdio> #include & ...

  9. HDU 4081 Qin Shi Huang's National Road System 最小生成树+倍增求LCA

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4081 Qin Shi Huang's National Road System Time Limit: ...

随机推荐

  1. OS中处理机调度模型和调度算法

    OS中处理机调度模型和调度算法 调度层次 1.1. 高级调度(长程调度,作业调度) 功能:依据某种算法.把在外存队列上处于后备队列的那些作业调入内存.以作业为操做对象. 作业:比程序更为广泛的概念,不 ...

  2. POJ 2386 Lake Counting 搜索题解

    简单的深度搜索就能够了,看见有人说什么使用并查集,那简直是大算法小用了. 由于能够深搜而不用回溯.故此效率就是O(N*M)了. 技巧就是添加一个标志P,每次搜索到池塘,即有W字母,那么就觉得搜索到一个 ...

  3. Java定时任务的三种实现方法

    译者注:个人觉得用定时任务来跑垃圾回收不是很好的例子,从译者接触到的项目来看,比较常见的是用定时任务来进行非实时计算,清除临时数据.文件等.在本文里,我会给大家介绍3种不同的实现方法:1.普通thre ...

  4. ODOO Unable To Find Wkhtmltopdf On This System. Error/Bug ?

    If you are using ODOO version 8 and getting some error like – Unable to find Wkhtmltopdf on this sys ...

  5. jquery autoComplete的使用代码一则

    $(function() { $("#vipCustomer").autocomplete({ source : function(request, response) { $.a ...

  6. spring学习笔记(五)

    1.后置通知 需求:调用相应业务方法后,完成资源的关闭. a. 在beans.xml中配置 .... <beans> <!--配置被代理对象--> <bean id=&q ...

  7. 工作总结 input 限制字数 textarea限制字数

    最大能输入50个字 复制粘贴也不行 <textarea maxlength="50"  class=" smallarea" cols="60& ...

  8. springboot学习(三) springboot文件配置

    1.简介 springboot没有了原来自己整合Spring应用时繁多的XML配置内容,替代它的是在pom.xml中引入模块化的Starter POMs,其中各个模块都有自己的默认配置,所以如果不是特 ...

  9. 使用GraphicsMagick/ImageMagick批量对图片瘦身

    GrahpicsMagick: find . -iname "*.jpg" -exec gm convert -strip +profile "*" -qual ...

  10. 转载-好用的linux软件合集

    音频 Airtime – Airtime 是一款用于调度和远程站点管理的开放广播软件  Ardour – 在 Linux 上录音,编辑,和混音  Audacious – 开源音频播放器,按你想要的方式 ...