题目链接: 题目 Underground Cables Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu 问题描述 A city wants to get rid of their unsightly power poles by moving their power cables underground. They have a list of points that all need to be con…
题意: 就是裸的最小生成树(MST), 完全图, 边长是实数. 分析: 算是复习一下MST把 方法一: prim 复杂度(n^2) #include <bits/stdc++.h> using namespace std; ; const int inf = 0x3f3f3f3f; double G[maxn][maxn], dis[maxn]; bool vis[maxn]; int x[maxn], y[maxn]; int N; double p2pdis(int x1, int y1,…
简单的最小生成树,不过中间却弄了很久,究其原因,主要是第一次做生成树,很多细节不够熟练,find()函数的循环for判断条件是 pre[i]>=0,也就是遇到pre[i]==-1时停止,i就是并查集的代表元. #include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #define MAXN 1000 #define MAXE 1000010 #define LEN…
POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:http://poj.org/ 1062* 昂贵的聘礼 枚举等级限制+dijkstra 1087* A Plug for UNIX 2分匹配 1094 Sorting It All Out floyd 或 拓扑 1112* Team Them Up! 2分图染色+DP 1125 Stockbroker…
Tangled in Cables Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6348   Accepted: 2505 Description You are the owner of SmallCableCo and have purchased the franchise rights for a small town. Unfortunately, you lack enough funds to start…
You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may connect pairs of points. For each possible route between two points,…
layout: post title: 训练指南 UVALive - 5713(最小生成树 + 次小生成树) author: "luowentaoaa" catalog: true mathjax: true tags: - 最小生成树 - 图论 - 训练指南 Qin Shi Huang's National Road System UVALive - 5713 题意 有n个城市,要修一些路使得任意两个城市都能连通.但是有人答应可以不计成本的帮你修一条路,为了使成本最低,你要慎重选择修…
Tangled in Cables Time Limit: 2 Seconds      Memory Limit: 65536 KB You are the owner of SmallCableCo and have purchased the franchise rights for a small town. Unfortunately, you lack enough funds to start your business properly and are relying on pa…
题目链接:https://vjudge.net/problem/UVALive-5713 题意:给出t组数据,每组数据第一行给出一个n,表示点的数量,接下来n行,每行有三个数字,分别是点的坐标x,y和点的值w.现在我们要用n-1条边来连接这n个点,秦始皇希望这n-1条边的权值之和最小,现在徐福说他可以让其中一条边的权值为0,但是他希望这条边所连接的两点的值之和最大,所以秦始皇决定使A/B的值最大,其中,A是徐福选择的那条边所连接两点的值的和,B是除徐福选择的边之外,其他n-2条边的权值之和,输出…
题目链接:https://vjudge.net/contest/241341#problem/D 这里有多个发电站,需要求出所有点都和发电站直接或间接相连的最小代价,那么就是求出最小生成树的问题了,有点细微的不同是我们一开始要把所有的发电站看成起点(看成一个点),把其他点到发电站的最小代价求出,之后就是模板题了. 代码: #include<iostream> #include<cstring> using namespace std; const int inf=0x3f3f3f;…
题意: 秦始皇修路,已知n个城市的坐标以及该城市的人口数,修路的费用是两个城市之间的欧几里得距离,其中可以有一条路不用花费代价但是要求这条路连接的两个城市的人口之和A/B尽量大,其中B是修路的总费用. 输入t组数据 输入n城市个数 输入n行x,y,z表示坐标和人口数 输出A/B. 代码: //类似次小生成树的处理方法,先求出最小生成树值ans,枚举要选的边u-v,ans减去u-v路径中的最大权值之后比较比值大小. #include<iostream> #include<cstdio>…
Network Time limit: 1.0 secondMemory limit: 64 MB Andrew is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the company, they can be connected to each other using cables. Since each w…
Networking 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/B Description You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the…
题目连接:problemId=542" target="_blank">ZOJ 1542 POJ 1861 Network 网络 Network Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Andrew is working as system administrator and is planning to establish a new network in his com…
题意  给你n个点 m条边  求最小生成树的权 这是最裸的最小生成树了 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N = 55, M = 3000; int par[N], n, m, ans; struct edge{int u, v, w;} e[M]; bool cmp(edge a, edge b){return a.w < b…
POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径) Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shar…
Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course.Farmer John ordered a high speed connection for his farm and is going to share his…
kruskal算法和prim算法 都说 kruskal是加边法,prim是加点法 这篇解释也不错:这篇 1.kruskal算法 因为是加边法,所以这个方法比较合适稀疏图.要码这个需要先懂并查集.因为我不会画好看的图,所以看不懂的话推荐下面博客的说明.这里是下面. 步骤: 1.把每个点都看成一棵树,那么你就会得到一片森林... 2.把每棵树之间的距离从小到大排序,即把边排序 3.从小到大取边,把不在同一棵树的点连通到同一棵树上...最后你会得到一棵树,就是最小生成树 我去盗图...这里的图 给个模…
Description You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may connect pairs of points. For each possible route between…
Network Time Limit: 1000MS   Memory Limit: 30000K          Special Judge http://poj.org/problem?id=1861 Description Andrew is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the compa…
解题报告 题目传送门 题意: 使得学校网络互通的最小花费,一些楼的线路已经有了. 思路: 存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树 #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #define inf 0x3f3f3f3f using namespace std; int n,m,_hash[1110][1110],vis…
Description In China, there are two companies offering the Internet service for the people from all cities: China Telecom and China Unicom. They both are planning to build cables between cities. Obviously, the government wants to connect all the citi…
题意:连通各点最短距离,最小生成树. You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may connect pairs of points. For each possible route…
以此图为例: package com.datastruct; import java.util.Scanner; public class TestKruskal { private static class Edge{ public Edge(int begin,int end,int weight){ this.begin = begin; this.end = end; this.weight = weight; } int begin; int end; int weight; publ…
最小生成树计数 (1s 128M) award [问题描述] 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的最小生成树.(如果两颗最小生成树中至少有一条边不同,则这两个最小生成树就是不同的).由于不同的最小生成树可能很多,所以你只需要输出方案数对31011的模就可以了. [输入格式] 第一行包含两个数,n和m,其中1<=n<=100; 1<=m<=1000; 表示该无向图的节点数和边数.每个节点用1~n的整数编号.接下来的m行,每行…
poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23507   Accepted: 11012 Description The Head Elder of the tropical island of Lagrishan has a problem. A b…
http://www.lydsy.com/JudgeOnline/problem.php?id=1016 统计每一个边权在最小生成树中使用的次数,这个次数在任何一个最小生成树中都是固定的(归纳证明). 在同一个边权上对所有边权为这个的边暴力统计(可以用矩阵树定理),然后用并查集把这个边权的所有边贡献的连通性都加上,再统计下一个边权. 最后把答案乘起来. #include<cstdio> #include<cstring> #include<algorithm> usin…
Prim算法 1.概览 普里姆算法(Prim算法),图论中的一种算法,可在加权连通图里搜索最小生成树.意即由此算法搜索到的边子集所构成的树中,不但包括了连通图里的所有顶点(英语:Vertex (graph theory)),且其所有边的权值之和亦为最小.该算法于1930年由捷克数学家沃伊捷赫·亚尔尼克(英语:Vojtěch Jarník)发现:并在1957年由美国计算机科学家罗伯特·普里姆(英语:Robert C. Prim)独立发现:1959年,艾兹格·迪科斯彻再次发现了该算法.因此,在某些场…
这个东西代码我是对着Trinkle的写的,所以就不放代码了.. Delaunay剖分的定义: 一个三角剖分是Delaunay的当且仅当其中的每个三角形的外接圆内部(不包括边界)都没有点. 它的存在性是调整法可证的. 最小生成树的性质: 对于每个环c,它上面最长的边一定有一条不在MST上. Delaunay剖分的性质: 如果有一条边的两个端点在一个内部(包括边界)没有其他点的圆上,那么这条边一定在Delaunay剖分内(反证). 那么如果有一条边u,v不在一个Delaunay剖分上,那么在任何一个…
最近都是图,为了防止几次记不住,先把自己理解的写下来,有问题继续改.先把算法过程记下来: prime算法:                  原始的加权连通图——————D被选作起点,选与之相连的权值最小的边              选与D.A相连权值最小的边——————可选的有B(7).E(8).G(11)                   ————————————————————————重复上述步骤,最小生成树 代码: 用maze[M][M]存两点间的长度,vis[M]判断是否使用此边,…