Electrification Plan Time limit: 0.5 secondMemory limit: 64 MB Some country has n cities. The government has decided to electrify all these cities. At first, power stations in k different cities were built. The other cities should be connected with t…
http://acm.timus.ru/problem.aspx?space=1&num=1982 1982. Electrification Plan Time limit: 0.5 secondMemory limit: 64 MB Some country has n cities. The government has decided to electrify all these cities. At first, power stations in k different cities…
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1982 题意:无向图,给n个点,n^2条边,每条边有个一权值,其中有k个点有发电站,给出这k个点的编号,选择最小权值的边,求使得剩下的点都能接收到电. 发电站之间显然不能有边,那么把k个点合成一个点,然后在图上就MST就可以了. //STATUS:C++_AC_31MS_401KB #include <functional> #include <algorithm> #in…
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=50#problem/D 最小生成树模板,注意的是这里有k个发电站,它们不再需要连接其他的发电站,所以任何两个发电站之间的权值是0: #include<stdio.h> #include<string.h> ; const int INF = 0x3f3f3f3f; int map[maxn][maxn],power[maxn]; int n,k; void pri…
题目 题意: 无向图,给n个城市,n*n条边,每条边都有一个权值 代表修路的代价,其中有k个点有发电站,给出这k个点的编号,要每一个城市都连到发电站,问最小的修路代价. 思路: prim:把发电站之间e[i][j]都设置为0,然后模板套进去就行. krusl:把所有的发电站都先弄进一个并查集(做法比较机智,先拿其中一个发电站,把剩下的发电站分别与这个发电站找父节点,分别弄进并查集就行). 然后按权值从小到大 排序,不是同一个并查集的就sum+=,再弄进并查集. 复杂度O(n*n) #includ…
Electrification Plan 时间限制: 1 Sec  内存限制: 128 MB提交: 31  解决: 13[提交][状态][讨论版] 题目描述 Some country has n cities. The government has decided to electrify all these cities. At first, power stations in k different cities were built. The other cities should be…
Electrification Plan 题意:在一个无向图中,给你几个源点,找出把所有点连接到源点后最小的消费: 可以利用并查集: 先用结构体把每个边存起来,再按照消费大小排序.之后从消费小的到大的一个个尝试,两个点需要连接的话,连接上同时把消费也算上去: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <string>…
Non-Yekaterinburg Subway Time limit: 1.0 secondMemory limit: 64 MB A little town started to construct a subway. The peculiarity of the town is that it is located on small islands, some of them are connected with tunnels or bridges. The mayor is sure…
Electrification Plan Prim #include<iostream> #include<cstring> using namespace std; const int INF = 0x3f3f3f3f; ; int n, k; int dis[N], ct[N][N], vis[N]; int Prim() { ; memset(vis, , sizeof(vis)); /* for(int i = 1; i <= n; i++) dis[i] = ct[…
题意  一个城市原来有l个村庄 e1条道路  又添加了n个村庄 e2条道路  后来后销毁了m个村庄  与m相连的道路也销毁了  求使全部未销毁村庄相互连通最小花费  不能连通输出what a pity! 还是非常裸的最小生成树  把销毁掉的标记下  然后prim咯  结果是无穷大就是不能连通的 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N =…