
图论
文章平均质量分 55
ctsas
这个作者很懒,什么都没留下…
展开
-
Til the Cows Come Home
Til the Cows Come Home (最短路问题)Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty原创 2017-01-26 17:56:37 · 286 阅读 · 0 评论 -
畅通工程再续
相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现。现在政府决定大力发展百岛湖,发展首先要解决的问题当然是交通问题,政府决定实现百岛湖的全畅通!经过考察小组RPRush对百岛湖的情况充分了解后,决定在符合条件的小岛间建上桥,所谓符合条件,就是2个小岛之间的距离不能小于10米,也不能大于1000米。当然,为了节省资金,只要求实现任意2个小岛原创 2017-02-01 18:54:43 · 280 阅读 · 0 评论 -
最小生成树个数
在存在权值相等的边时,最小生成树可能有多个。话不多说,求它个数的方法如下:先用Prim生成最小树,同时记录边的关系。用并查集表示//不要压缩路径让每个元素都指向它的父亲节点。找出权值相同的边,去除树上的这条边,一棵树就被砍成了两颗,然后看加上另一条是否能连接这科树方法就是这样,复杂度O(|E|log|E|)具体问题:输入第一行:T //代表T组数据 每组数据:V E //代表V个顶点 E条边E原创 2017-02-02 15:49:10 · 6705 阅读 · 2 评论 -
图论算法及其模板
什么方法好,和数据关系很大,和你使用的数据结构也有关。比如使用vector,它自身就有复杂度,所以在稠密图上不及二维数组的邻接矩阵,但在稀疏图方面肯定vector的动态数组实现的链接列表更好。有些复杂度高的算法,其实际体验可能比复杂度低的更快,因为复杂度是按最糟糕的情况算的,而且复杂度低的算法往往是使用数据结构优化而实现的,而实现数据结构也是存在复杂度的,所以会出现这些个情况。原创 2017-03-01 22:04:37 · 582 阅读 · 0 评论 -
单链表表示边权
Til the Cows Come HomeBessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep,原创 2017-03-09 11:01:22 · 379 阅读 · 0 评论 -
[HDU] 3549 Flow Problem [最大流][Dinic][读取优化]
Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph.Input The first line of input c原创 2017-04-07 22:10:05 · 395 阅读 · 0 评论 -
[LightOJ - 1330] Binary Matrix [最大流][Dinic]
A binary matrix is an m x n matrix consisting of only zeroes and ones. Now you are given m integers, ith integer indicating the summation of the values of cells in ith row. You are also given n integer原创 2017-04-08 17:43:37 · 623 阅读 · 0 评论 -
[poj] 1273 Drainage Ditches[最大流][Ford-Fulkerson]
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K DescriptionEvery time it rains on Farmer John’s fields, a pond forms over Bessie’s favorite clover patch. This means that the clover i原创 2017-04-01 12:45:33 · 325 阅读 · 0 评论 -
[csu] 1175: A Tour Around Hangzhou [最短路][压缩DP][模板题]
Description swimming来到杭州旅行,杭州是个美丽的城市,有很多美丽的景点.但让他头痛的是这些景点之间都有很长的距离,swimming决定选择便宜快捷的公交作为交通工具.杭州的公交网也十分复杂,不同的景点之间要转很多次公交才能到达,已知这些公交都只能站点上下车,并且相同的两个站点之间可能会有多班公交车.swimming想让你帮他设计一条旅游线路,花最少的钱旅游完所有原创 2017-04-11 16:13:15 · 349 阅读 · 0 评论 -
[HPU] 机房的位置(三)[二分图最大匹配][匈牙利算法]
题目描述 还记得之前的机房位置问题吗?某天有n个学长来到机房,发现机房有m个空位。据了解,每个学长都有自己所喜欢的位置,而且他们都不愿意坐自己不喜欢的位置。现在我想知道最少会有多少个学长得不到位置。学长编号从1-n,位置编号从1-m。输入 有t组测试数据,每组数据第一行是两个整数n和m,接下来有n行,第i+1行开头是一个整数p[i],接下来跟着p[i]个整数代表第i个学长所喜欢的位置编号。(1原创 2017-03-16 22:06:47 · 430 阅读 · 0 评论 -
Arctic Network
The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every ou原创 2017-02-01 17:30:59 · 356 阅读 · 0 评论 -
QS Network
Sunny Cup 2003 - Preliminary RoundApril 20th, 12:00 - 17:00Problem E: QS NetworkIn the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunicate with each oth原创 2017-01-31 17:47:14 · 389 阅读 · 0 评论 -
Constructing Roads
There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if and only if th原创 2017-01-31 15:41:01 · 216 阅读 · 0 评论 -
Silver Cow Party
Silver Cow Party (最短路)One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidi原创 2017-01-26 21:24:45 · 363 阅读 · 0 评论 -
Frogger
Frogger(最短路的变形)Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of原创 2017-01-27 11:13:27 · 335 阅读 · 0 评论 -
Heavy Transportation
Heavy Transportation(变形最短路问题)Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is原创 2017-01-27 15:18:52 · 349 阅读 · 0 评论 -
Cow Contest [最短路][floyd]
N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is uni原创 2017-02-23 10:03:07 · 272 阅读 · 0 评论 -
负环图检测
探讨负环图的最短路问题是没有意义的。 由于Bellman-Ford算法while(true)最多执行|V|-1次,如果第|V|次还进行了更新那么就还要继续执行|V|次了,通过这个特新便可o(|V|*|E|)判断负环图了。struct edge{int from,to,cost;};edge es[MAX_E];int d[MAX_V];int V,E;bool check(){原创 2017-01-29 20:12:11 · 1380 阅读 · 0 评论 -
kruskal 生成最小树
kruskal 算法在排序上最费时,生成树过程复杂度是线性的,所以最终复杂度为o(|E|log|V|)。 可以对比一下prim算法 传送门》》题目链接#include<stdio.h>#include<string.h>#include<queue>#include<algorithm>#define INF 0x3f3f3f3fusing namespace std;int cos原创 2017-01-31 10:28:11 · 900 阅读 · 0 评论 -
prim 最小生成树
prim 最小生成树从单一顶点开始,普里姆算法按照以下步骤逐步扩大树中所含顶点的数目,直到遍及连通图的所有顶点。输入:一个加权连通图,其中顶点集合为V,边集合为E;初始化:Vnew = {x},其中x为集合V中的任一节点(起始点),Enew = {};重复下列操作,直到Vnew = V:在集合E中选取权值最小的边(u, v),其中u为集合Vnew中的元素,而v则是V中没有加入Vnew的顶点(原创 2017-01-30 23:24:56 · 342 阅读 · 0 评论 -
无向图最小生成树
问题N个点M条边的无向连通图,每条边有一个权值,求该图的最小生成树。Input第1行:2个数N,M中间用空格分隔,N为点的数量,M为边的数量。(2 <= N <= 1000, 1 <= M <= 50000) 第2 - M + 1行:每行3个数S E W,分别表示M条边的2个顶点及权值。(1 <= S, E <= N,1 <= W <= 10000)Output输出最小生成树的所有边的权值之和。题原创 2017-01-31 11:51:31 · 1433 阅读 · 0 评论 -
Building a Space Station
You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write a computer program to complete the task. The spac原创 2017-01-31 14:50:48 · 313 阅读 · 0 评论 -
UESTC - 1431 不是图论 [强连通分量分解][并点]
给出一个n个点,m条边的有向图。每个点上有分值,经过这个点时可以获得一定的分数。一个点可以经过多次,但是一个点上的分数只能获得一次。问最多能获得多少分数,起点任选。1<=n<=30000,1<=m<=100000Input 输入包含多组数据每组数据第一行为n,m 接下来n行,每行有一个数,表示第ii个节点的分值。接下来m行,每行有两个数a、b,表示有一条从a到b的有向边Output 每组数据输原创 2017-04-15 21:28:55 · 488 阅读 · 0 评论