图论
破晓aa
这个作者很懒,什么都没留下…
展开
-
Dijkstra 算法求最短路径
以oj 2134题 图结构练习——最短路径为例 #include <iostream> #include <climits> #define INF 0x3f3f3f3f using namespace std; int dist[200], gra[200][200], vis[200]; int n; void Dijkstra(int begins) { in...原创 2018-05-18 21:05:09 · 1072 阅读 · 0 评论 -
Popular Cows POJ - 2186 (Tarjan求强连通分量 + 缩点)
Every cow’s dream is to become the most popular cow in the herd. In a herd of N (1 &lt;= N &lt;= 10,000) cows, you are given up to M (1 &lt;= M &lt;= 50,000) ordered pairs of the form (A, B) that tel...原创 2019-01-09 15:34:36 · 148 阅读 · 0 评论 -
tarjan求强连通分量+缩点+割点/割桥(点双/边双)
转载自 这里 一、tarjan求强连通分量 1、什么是强连通分量? 引用来自度娘的一句话: “有向图强连通分量:在有向图G中,如果两个顶点vi,vj间(vi>vj)有一条从vi到vj的有向路径,同时还有一条从vj到vi的有向路径,则称两个顶点强连通(strongly connected)。如果有向图G的每两个顶点都强连通,称G是一个强连通图。有向图的极大强连通子图,称为强连通分量(...转载 2019-01-09 10:57:47 · 380 阅读 · 1 评论 -
The Cow Prom POJ - 3180 (Tarjan求强连通分量)
The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their finest gowns, complete with corsages and new shoes. They know that tonight they will each try to perform ...原创 2019-01-08 21:44:49 · 129 阅读 · 0 评论 -
Caocao's Bridges HDU - 4738(Tarjan求割边模板题)
题目链接 题目意思: 求割边 #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 1010; int n, m, tot, num; int head[maxn], dfn[maxn], low[maxn]; boo...原创 2019-01-11 20:42:20 · 269 阅读 · 0 评论 -
B - Network of Schools POJ - 1236(Tarjan求强连通分量+缩点)
题目链接 题意: 给出你一个图,代表许多学校的网络连接情况,第一个问题:要想把一个信息传输到所有节点至少要在几个节点上放置信息。第二个问题:想要把整个图变成强连通图需要增加多少条边。 思路: 对于第一个问题,找到所有的强连通分量,然后把其缩成一个点,然后再看整个图,统计一下入度为0的点,就是答案(PS:注意整个图是强连通图,也就是入度为0的点不存在,这时应该输出1)。 对于第二个问题,还是和...原创 2019-01-11 20:05:00 · 174 阅读 · 0 评论 -
Redundant Paths POJ - 3177 (求割边 + 缩点)
In order to get from one of the F (1 &amp;lt;= F &amp;lt;= 5,000) grazing fields (which are numbered 1…F) to another field, Bessie and the rest of the herd are forced to cross near the Tree of Rotten Apples. ...原创 2019-01-11 16:33:27 · 160 阅读 · 0 评论 -
求图的最小环
说到求图的最小环,比较常见的是Floyed求,复杂度为O(n^3),比较费时。再优一点的,枚举所有边,每次删去一条边(u, v),然后从u开始跑Dijkstra(用堆或者c++中优先队列优化的)求u到v的距离再加上(u, v)的权值,枚完玩所有边就得出答案了,复杂度为O(m * n * logn)。然而这样的复杂度还是不令人满意。 看了好多博客,倒是发现了一个比较优的方法,我们先求所给图的最小生...原创 2018-12-14 21:07:46 · 4028 阅读 · 7 评论 -
Magical Girl Haze (分层图 + 最短路径优先队列优化)
There are NNN cities in the country, and MMM directional roads from uuu to v(1≤u,v≤n)v(1\le u, v\le n)v(1≤u,v≤n). Every road has a distance cic_ici. Haze is a Magical Girl that lives in City 111, she...原创 2018-09-03 21:16:32 · 362 阅读 · 0 评论 -
I - Candies POJ - 3159 (数组模拟邻接表+栈优化spfa)
During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of flymouse’s class a large bag of candies and had flymouse distribute them. All the...原创 2018-08-02 15:29:51 · 212 阅读 · 0 评论 -
SPFA 算法
~SPFA算得上是bellman-ford算法优化,采用的是动态逼近的方法,对dist数组进行一次次的更新,最后得出最终的最短路径。再捎带说一点Dijkstra与SPFA的适用情况以及一些不同之处。Dijkstra是每次确定了到一个点的最短距离,再用该点更新到其它点的距离。不能处理有负边的图。Bellman-Ford是每次对所有边松弛。可以计算出有负边无负环的最短路,可以判断是否存在负环。使用邻接...原创 2018-07-15 11:23:22 · 307 阅读 · 0 评论 -
Network POJ - 1144(Tarjan求割点)
A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The lines are bi...原创 2019-01-09 21:35:20 · 148 阅读 · 0 评论