
图论专项
人面桃花相映红
BNU student
展开
-
并查集
int father[100];//储存i的father父节点 void makeSet() { for (int i = 0; i < 100; i++) father[i] = i; } int findRoot(int x) { //递归查找根节点 if (father[x] == x)原创 2016-09-19 18:54:21 · 278 阅读 · 0 评论 -
hdu 1874 最短路问题 地杰斯特拉算法及其heap优化
#include <iostream>#include <cstdio>#include <vector>#define Min(x,y) ( (x) < (y) ? (x) : (y) )using namespace std;const int maxn = 205;const int INF = 0x3f3f3f3f;struct Node{ int vex,weigh原创 2016-10-16 11:10:37 · 324 阅读 · 0 评论 -
hdu 1116 poj 1386 欧拉回路并查集
#include#include#include#include#includeusing namespace std;const int maxn =30;int pre[maxn],in[maxn],out[maxn];int n; int num, len; //单词个数,每个单词长度 int start, End; //转化为边原创 2017-04-26 18:29:23 · 290 阅读 · 0 评论 -
hdu 1272 小希的迷宫 并查集
题意:给你任意多的两个点,让你判断从一个点到另一个点是不是只有唯一的一条路径思路:只要是两个点的根节点是一样的,说明已经成环了,至少有两种方式进行遍历了,所以肯定是不行的。而且并不是所有的点都是被用到的 ,所以需要判断一下是不是所有的点是不是在一个联通分量里面。#include#includeusing namespace std;const int N = 100005;int原创 2017-05-26 16:20:09 · 436 阅读 · 0 评论 -
poj 1251 最小生成树
原题:http://poj.org/problem?id=1251 Total Submissions: 12886 Accepted: 5760DescriptionThe Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on e原创 2017-03-29 18:56:24 · 245 阅读 · 0 评论 -
hdu1874 畅通工程续 Bellman-Ford算法SPFA
连接:http://acm.hdu.edu.cn/showproblem.PHP?pid=1874Problem Description 某省自从实行了很多年的畅通工程计划后,终于修建了很多路。不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多。这让行人很困扰。现在,已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离原创 2016-10-17 09:21:05 · 232 阅读 · 0 评论 -
hdu1233 还是畅通工程 最小生成树 Prim算法堆优化
Prim算法优化版,用堆时间复杂度:O(elgn)[cpp] view plain copyprint?在CODE上查看代码片派生到我的代码片 struct node { int v, len; node(int v = 0, int len = 0) :v(v), len(len) {} bool operator < (cons原创 2016-09-21 08:52:18 · 413 阅读 · 0 评论 -
文章标题
图论(6+): Dijkstra算法详解和拓展优化 先上伪码伪码在于指出算法的思路, 下面我们用伪码来分析迪杰斯塔特拉的思路void Dijkstra(table T){ vertex v, w; for (;;) { v = smallest unknown distance vertex; if (v == notavrtex)转载 2016-10-14 21:07:01 · 170 阅读 · 0 评论 -
最短路大全
图论(6): 单源赋值图最短路径 总括单源最短路径问题在前几篇已经提到过,在这里不再赘述。有额外的一点, 终点和起点都固定的问题称之为:两点之间最短路径问题。但是因为解决单源最短路径问题的时间复杂度也是一样的, 因此通常当作单源最短路径问题处理(在求单源最短路径的同时求出的实际是单点到全图说有点的最短路径)下面我将讲解最短路径的三种常见算法: Bellman-ford算法 Dijkstra算法 F转载 2016-10-14 21:03:57 · 424 阅读 · 0 评论 -
POJ 1308
Is It A Tree? Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu Submit Status Practice POJ 1308Description A tree is a well-known data structure that is either empty (null,原创 2016-10-23 22:25:15 · 191 阅读 · 0 评论 -
nyoj 20 转换根节点
思想:通过一个dfs,以递归的思想搜索当前建树节点的父节点,直到找到最后的根节点,每个过程中把父节点倒置,然后把根节点的父节点置为所要求的节点,然后根据当时所存的父节点,一个一个输出#include <stdio.h>#include <string.h>#define MAX 100001int fa[MAX];//代表问题解,即从S到达第 i个城市必须经过的前一个城市void dfs(原创 2016-09-25 19:40:56 · 224 阅读 · 0 评论 -
.Floyd-Warshall算法——任意点对最短路算法
//Floyd-Warshall算法——任意点对最短路算法//求图中任意两点的最短距离的算法 for (int i = 0; i < n; i++) {//初始化为0 for (int j = 0; j < n; j++) scanf("%lf", &dis[i][j]);原创 2016-09-21 09:42:47 · 622 阅读 · 0 评论 -
hdu 1233 prim 算法
prim算法int Prim(int s)//s是第一个加入生成树的结点{ int ans = 0; int vex,addNode,tempMin;//加入集合F中的节点 intree[s] = true;//加入生成树 for(unsigned int i = 0 ; i < G[s].size() ; ++i){//更新mindistG[s][i].vex即所原创 2016-09-20 21:50:17 · 195 阅读 · 0 评论 -
hdu 1233(最小生成树问题) 克鲁斯卡尔算法
#include <stdio.h>#include <iostream>#include <algorithm>using namespace std;struct node{ int a,b,len;}G[5055];int cmp(const node &a,const node &b){ return a.len<b.len;}int father[120]原创 2016-09-20 17:34:29 · 297 阅读 · 0 评论 -
染色法
bool bicolorable(){//染色法 queueQ; color[0]=1; Q.push(0); while(!Q.empty()){ int v1 = Q.front(); Q.pop(); for(int i=0;i原创 2016-09-04 10:32:09 · 429 阅读 · 0 评论 -
C++ Dijkstra算法 带路径输出 vector存图
该算法可以求任意两点之间的最短路,并且输出路径点。#include <iostream>#include <cstdio>#include <vector>#define Min(x,y) ( (x) < (y) ? (x) : (y) )using namespace std;const int maxn = 205;const int I...原创 2019-04-18 12:00:35 · 799 阅读 · 0 评论