图论——图的连通性
文章平均质量分 90
Alex_McAvoy
想要成为渔夫的猎手
展开
-
图论 —— 图的连通性
【基本概念】1.连通图与连通分量1)连通图:无向图 G 中,若对任意两点,从顶点 Vi 到顶点 Vj 有路径,则称 Vi 和 Vj 是连通的,图 G 是一连通图2)连通分量:无向图 G 的连通子图称为 G 的连通分量 任何连通图的连通分量只有一个,即其自身,而非连通的无向图有多个连通分量 以上图为例,总共有四个连通分量,分别是:ABCD、E、FG、HI。...原创 2018-10-20 21:18:40 · 20352 阅读 · 0 评论 -
图论 —— 图的连通性 —— 并查集判断连通性
当需要判断图是否为连通图时,可以使用并查集来进行连通分量的统计,若连通分量大于 1,则说明图中存在多个连通分量,图不为连通图。int n,m;int father[N];int Find(int x){ if(father[x]==-1) return x; return father[x]=Find(father[x]);}void Union(in...原创 2019-01-30 14:52:15 · 5946 阅读 · 1 评论 -
图论 —— 图的连通性 —— 传递闭包
【概述】传递闭包:对于一个节点 i,如果 j 能到 i,i 能到 k,那么 j 就能到 k,求传递闭包,就是把图中所有满足这样传递性的节点计算出来,计算完成后,就知道任意两个节点之间是否相连。简单来说,传递闭包是一种关于连通性的算法,其是指所有点的所能到达的点集。【传递闭包的计算】Floyd 可以用来判断图中两点是否连通,在求连通性的同时,可以进行传递闭包计算。对于一个没有边权...原创 2019-08-17 08:57:07 · 5528 阅读 · 1 评论 -
图论 —— 图的连通性 —— Kosaraju 算法
【概述】Kosaraju 算法是最容易理解,最通用的求强连通分量的算法,其关键的部分是同时应用了原图 G 和反图 GT 。【基本思想】1.对原图 G 进行 DFS 搜索,计算出各顶点完成搜索的时间 f2.计算图的反图 GT,对反图也进行 DFS 搜索,但此处搜索时顶点的访问次序不是按照顶点标号的大小,而是按照各顶点 f 值由大到小的顺序3.反图 DFS 所得到的森林即对应连通区...转载 2019-01-30 14:54:57 · 2402 阅读 · 0 评论 -
图论 —— 图的连通性 —— Tarjan 求强连通分量
【概述】Tarjan 算法是基于对图深度优先搜索的算法,每个强连通分量为搜索树中的一棵子树。搜索时,把当前搜索树中未处理的节点加入一个堆栈,回溯时可以判断栈顶到栈中的节点是否为一个强连通分量。【基本思路】定义 DFN(u) 为节点 u 搜索的次序编号(时间戳),即是第几个被搜索到的,Low(u) 为 u 或 u 的子树能够追溯到的最早的栈中节点的次序号。每次找到一个新点 i,有...转载 2019-01-30 15:00:06 · 1107 阅读 · 0 评论 -
图论 —— 图的连通性 —— Tarjan 缩点
缩点常应用于给一个有向图,求在图中最少要加多少条边能使得该图变成一个强连通图首先求出该图的各个强连通分量,然后把每个强连通分量看出一个点(即缩点),最后得到了一个有向无环图(DAG)对于一个DAG,需要添加 max(a,b) 条边才能使其强连通其中 a 为 DAG 中出度为 0 的点总数,b 为 DAG 中入度为 0 的点总数int n,m;vector<int> ...原创 2019-01-30 15:01:55 · 722 阅读 · 0 评论 -
图论 —— 图的连通性 —— Tarjan 求割点与桥
【概念】1.割点1)割点:删除某点后,整个图变为不连通的两个部分的点2)割点集合:在一个无向图中删除该集合中的所有点,能使原图变成互不相连的连通块的点的集合3)点连通度:最小割点集合点数如上图,若去掉 0,则图被分成 12和 34 两个连通分量;若去掉 3,则图被分成 012 和 4 两个连通分量。故:0、3 是割点,两者是一个割点集,点连通度是 22.桥1)...转载 2019-01-30 15:06:42 · 1614 阅读 · 0 评论 -
图论 —— 图的连通性 —— Tarjan 求双连通分量
【概念】1.双连通分量:对于一个无向图,其边/点连通度大于1,满足任意两点之间,能通过两条或两条以上没有任何重复边的路到达的图,即删掉任意边/点后,图仍是连通的2.分类: 1)点双连通图:点连通度大于 1 的图 2)边双连通图:边连通度大于 1 的图【原理】1.求点双连通分量求点双连通分量可以在求割点的同时用栈维护。在搜索图时,每找到一条树枝边或后向边(...原创 2019-01-30 15:10:43 · 1060 阅读 · 2 评论 -
图论 —— 图的连通性 —— 有桥连通图加边变边双连通图
对于一个有桥的连通图,加边变成边双连通图1.求出所有的桥,然后删除这些桥边。剩下的每个连通块都是一个双连通子图。2.把每个双连通子图收缩为一个顶点。3.加回桥边,统计度为1的节点的个数(叶节点的个数),记为 leaf则:至少在树上加(leaf+1)/2 条边,就能使树达到边双连通除使用两次 dfs 外,还可以使用 Tarjan 算法一次求出所有点的 low[i] 值,由于同一...原创 2019-01-30 16:43:21 · 1579 阅读 · 0 评论 -
Wireless Network(POJ-2236)
Problem DescriptionAn earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, ...原创 2019-02-18 18:04:55 · 588 阅读 · 0 评论 -
Critical Links(LightOJ - 1026)
Problem DescriptionIn a computer network a link L, which interconnects two servers, is considered critical if there are at least two servers A and B such that all network interconnection paths betw...原创 2019-01-23 20:03:42 · 370 阅读 · 0 评论 -
Hawk-and-Chicken(HDU-3639)
Problem DescriptionKids in kindergarten enjoy playing a game called Hawk-and-Chicken. But there always exists a big problem: every kid in this game want to play the role of Hawk.So the teacher ca...原创 2019-01-19 18:52:54 · 647 阅读 · 0 评论 -
Street Directions(POJ-1515)
Problem DescriptionAccording to the Automobile Collision Monitor (ACM), most fatal traffic accidents occur on two-way streets. In order to reduce the number of fatalities caused by traffic accident...原创 2019-01-14 18:56:45 · 382 阅读 · 0 评论 -
Dima and Bacteria(CF-400D)
Problem DescriptionDima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number o...原创 2019-01-17 20:09:29 · 383 阅读 · 0 评论 -
刻录光盘(信息学奥赛一本通-T1383)
【题目描述】在FJOI2010夏令营快要结束的时候,很多营员提出来要把整个夏令营期间的资料刻录成一张光盘给大家,以便大家回去后继续学习。组委会觉得这个主意不错!可是组委会一时没有足够的空光盘,没法保证每个人都能拿到刻录上资料的光盘,怎么办呢?!DYJ分析了一下所有营员的地域关系,发现有些营员是一个城市的,其实他们只需要一张就可以了,因为一个人拿到光盘后,其他人可以带着U盘之类的东西去拷贝...原创 2018-06-18 03:21:31 · 2646 阅读 · 0 评论 -
Cow Contest(POJ-3660 )
Problem DescriptionN (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 s...原创 2018-05-29 20:07:43 · 446 阅读 · 0 评论 -
Ranking the Cows(POJ-3275 )
Problem DescriptionEach of Farmer John's N cows (1 ≤ N ≤ 1,000) produces milk at a different positive rate, and FJ would like to order his cows according to these rates from the fastest milk produc...原创 2018-06-23 22:17:41 · 450 阅读 · 1 评论 -
珍珠(信息学奥赛一本通-T1384)
【题目描述】有n颗形状和大小都一致的珍珠,它们的重量都不相同。n为整数,所有的珍珠从1到n编号。你的任务是发现哪颗珍珠的重量刚好处于正中间,即在所有珍珠的重量中,该珍珠的重量列(n+1)/2位。下面给出将一对珍珠进行比较的办法:给你一架天平用来比较珍珠的重量,我们可以比出两个珍珠哪个更重一些,在作出一系列的比较后,我们可以将某些肯定不具备中间重量的珍珠拿走。例如,下列给出对5颗珍珠进...原创 2018-06-18 03:25:52 · 2084 阅读 · 0 评论 -
Network(POJ-1144)
Problem DescriptionA 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 nu...原创 2018-10-28 00:11:52 · 1090 阅读 · 0 评论 -
Strongly connected(HDU-4635)
Problem DescriptionGive a simple directed graph with N nodes and M edges. Please tell me the maximum number of the edges you can add that the graph is still a simple directed graph. Also, after you...原创 2018-10-24 21:18:48 · 353 阅读 · 0 评论 -
Equivalent Sets(HDU-3836)
Problem DescriptionTo prove two sets A and B are equivalent, we can first prove A is a subset of B, and then prove B is a subset of A, so finally we got that these two sets are equivalent.You are ...原创 2018-10-24 21:04:48 · 251 阅读 · 0 评论 -
TWO NODES(HDU-4587)
Problem DescriptionSuppose that G is an undirected graph, and the value of stab is defined as follows:Among the expression,G-i, -j is the remainder after removing node i, node j and all edges t...原创 2018-10-28 16:15:06 · 416 阅读 · 1 评论 -
Caocao's Bridges(HDU-4738)
Problem DescriptionCaocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. But he wouldn't give up. Caocao's army still was not good at water battles, so he came up with another idea...原创 2018-10-28 16:17:53 · 511 阅读 · 0 评论 -
By Recognizing These Guys, We Find Social Networks Useful(HDU-3849)
Problem DescriptionSocial Network is popular these days.The Network helps us know about those guys who we are following intensely and makes us keep up our pace with the trend of modern times.But h...原创 2018-10-28 16:19:14 · 253 阅读 · 0 评论 -
The Cow Prom(POJ-3180)
Problem DescriptionThe 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 wil...原创 2018-10-23 20:19:05 · 306 阅读 · 0 评论 -
Financial Crisis(HDU-3749)
Problem DescriptionBecause of the financial crisis, a large number of enterprises go bankrupt. In addition to this, other enterprises, which have trade relation with the bankrup enterprises, are al...原创 2018-10-29 10:07:49 · 485 阅读 · 0 评论 -
Road Construction(POJ-3352)
Problem DescriptionIt's almost summer time, and that means that it's almost summer construction time! This year, the good people who are in charge of the roads on the tropical island paradise of Re...原创 2018-10-29 10:08:25 · 771 阅读 · 0 评论 -
Redundant Paths(POJ-3177)
Problem DescriptionIn order to get from one of the F (1 <= F <= 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 ...原创 2018-10-29 10:08:53 · 286 阅读 · 0 评论 -
Network of Schools(POJ-1236)
Problem DescriptionA number of schools are connected to a computer network. Agreements have been developed among those schools: each school maintains a list of schools to which it distributes softw...原创 2018-10-24 18:27:44 · 321 阅读 · 0 评论 -
迷宫城堡(HDU-1269)
Problem Description为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每个通道都是单向的,就是说若称某通道连通了A房间和B房间,只说明可以通过这个通道由A房间到达B房间,但并不说明通过它可以由B房间到达A房间。Gardon需要请你写个程序确认一下是否任意两个房间都是相互连通的,即:对于任意的i...原创 2018-10-24 20:26:14 · 807 阅读 · 0 评论 -
Proving Equivalences(HDU-2767)
Problem DescriptionConsider the following exercise, found in a generic linear algebra textbook.Let A be an n × n matrix. Prove that the following statements are equivalent:1. A is invertible.2...原创 2018-10-24 20:48:06 · 271 阅读 · 0 评论 -
Islands(2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 F)
Problem DescriptionOn the mysterious continent of Tamriel, there is a great empire founded by human.To develope the trade, the East Empire Company is set up to transport goods from place to place...原创 2019-08-27 09:34:33 · 290 阅读 · 0 评论