
tarjan算法~~强连通分量
xuanweiace
一个热爱算法竞赛的弱校ACMer路过。青大本,浙大硕,方向后端开发,菜鸡一枚,奋斗ing...
展开
-
Tarjan 算法 常用模板
可以求每个点属于第几个强连通分量:https://blog.youkuaiyun.com/dellaserss/article/details/8267192int Tarjan(int u){ int v; dfn[u]=low[u]=++Index; stack[++Top]=u; Instack[u]=1; for(int i=0;i<G[u].siz...原创 2019-11-01 16:52:15 · 234 阅读 · 0 评论 -
【POJ - 3177】Redundant Paths(边双连通分量,去重边)
题干:In 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 Tree of Rotten Ap...原创 2019-07-16 18:07:31 · 288 阅读 · 0 评论 -
【POJ - 3352】Road Construction(Tarjan,边双连通分量)
题干:It'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 Remote Island would...原创 2019-07-16 18:09:46 · 335 阅读 · 0 评论 -
【POJ - 2942】Knights of the Round Table(点双连通分量,二分图判断奇环奇圈)
题干:Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress, and drinking with the other knights are fun things to do. Therefore, it is not very surprisin...原创 2019-07-19 18:30:04 · 369 阅读 · 0 评论 -
【HDU - 3394】Railway(点双连通分量,Tarjan算法,思维tricks)
题干:There are some locations in a park, and some of them are connected by roads. The park manger needs to build some railways along the roads, and he would like to arrange tourist routes to each circ...原创 2019-07-17 22:39:55 · 605 阅读 · 0 评论 -
【BZOJ - 2574】[Poi1999] Store-Keeper(点双连通分量,求割点,记忆化bfs)
题干:有一个仓库被分成n*m个矩形区域,如果两个区域有一条公共边,则被认为这两个区域相邻。包裹都放在一个区域中,剩余的区域或者空闲或者被集装箱占有,这是因为集装箱太重,仓库管理员不能将集装箱搬走。仓库管理员目是是要将包裹从开始的P区域移动到最后的K区域。他可以从空区域走到与之相邻的一个空区域。当仓库管理员走到与包裹相邻的区域时,它可以推动包裹,具体的推动方法如下所示:读入一个储藏表...原创 2019-07-19 18:29:47 · 655 阅读 · 0 评论 -
【POJ - 1523】SPF(Tarjan求割点,求分割成的连通块数,模板题,tricks)
题干:Consider the two networks shown below. Assuming that data moves around these networks only between directly connected nodes on a peer-to-peer basis, a failure of a single node, 3, in the network ...原创 2019-07-18 19:36:33 · 256 阅读 · 0 评论 -
【POJ - 3694】Network(对dfn求lca 或 缩点+lca 或 边双连通+并查集)
题干:网络管理员管理大型网络。该网络由N台计算机和成对计算机之间的M链路组成。任何一对计算机都通过连续的链接直接或间接连接,因此可以在任何两台计算机之间转换数据。管理员发现某些链接对网络至关重要,因为任何一个链接的故障都可能导致某些计算机之间无法转换数据。他把这种联系称为桥梁。他计划逐一添加一些新链接以消除所有桥梁。 您将通过在添加每个新链接后报告网络中的网桥数来帮助管理员。输入输入包...原创 2019-07-18 19:36:36 · 298 阅读 · 0 评论 -
【2019南昌邀请赛现场赛 - G】Winner(建图,tarjan缩点 或 贪心)
题目大意:n个人参加竞技比赛。比赛由三种模式a,b,c,每个人在每种模式下有对应的权值a[i]b[i]c[i]。举行n−1场比赛,每场比赛主办方可以选择两个人决斗,能力值低的人淘汰。这样保证n-1场比赛过后,只会有一个winner。q 个询问,询问第x个人,问主办方有没有一种方式可以使他成为winner。(n=1e5,q=1e5)解题报告:wjh大佬写的贪心也能过,但是这题正解是缩点。...原创 2019-09-06 15:56:27 · 272 阅读 · 0 评论 -
【POJ - 2553】The Bottom of a Graph(tarjan强连通分量缩点,模板题)
题干:We will use the following (standard) definitions from graph theory. LetVbe a nonempty and finite set, its elements being called vertices (or nodes). LetEbe a subset of the Cartesian productV...原创 2019-07-16 18:08:04 · 239 阅读 · 0 评论 -
【POJ - 2762】Going from u to v or from v to u?(Tarjan缩点,树形dp 或 拓扑排序,欧拉图相关)
题干:In order to make their sons brave, Jiajia and Wind take them to a big cave. The cave has n rooms, and one-way corridors connecting some rooms. Each time, Wind choose two rooms x and y, and ask on...原创 2019-05-06 22:56:33 · 224 阅读 · 0 评论 -
【POJ - 3160】Father Christmas flymouse(Tarjan缩点,DAG最长路)
题干:After retirement as contestant from WHU ACM Team, flymouse volunteered to do the odds and ends such as cleaning out the computer lab for training as extension of his contribution to the team. Whe...原创 2019-04-09 10:04:28 · 284 阅读 · 0 评论 -
【51nod - 1076】2条不相交的路径(Tarjan无向图判环)
题干:给出一个无向图G的顶点V和边E。进行Q次查询,查询从G的某个顶点V[s]到另一个顶点V[t],是否存在2条不相交的路径。(两条路径不经过相同的边)(注,无向图中不存在重边,也就是说确定起点和终点,他们之间最多只有1条路)收起输入第1行:2个数M N,中间用空格分开,M是顶点的数量,N是边的数量。(2 <= M <= 25000, 1 <= N <...原创 2019-03-13 21:15:50 · 791 阅读 · 0 评论 -
【蓝桥杯官网试题 - 历届试题】发现环(dfs+并查集,或无向图tarjan判环,无向环,或拓扑排序)
题干:问题描述 小明的实验室有N台电脑,编号1~N。原本这N台电脑之间有N-1条数据链接相连,恰好构成一个树形网络。在树形网络上,任意两台电脑之间有唯一的路径相连。 不过在最近一次维护网络时,管理员误操作使得某两台电脑之间增加了一条数据链接,于是网络中出现了环路。环路上的电脑由于两两之间不再是只有一条路径,使得这些电脑上的数据传输出现了BUG。 为了恢复正常传输。小明需要找到所有...原创 2019-03-13 22:02:11 · 521 阅读 · 0 评论 -
【HDU - 5934】Bomb (强连通分量Tarjan + 缩点)
题干:There areNNbombs needing exploding.Each bomb has three attributes: exploding radiusriri, position(xi,yi)(xi,yi)and lighting-costciciwhich means you need to paycicicost making it explod...原创 2019-03-10 14:50:20 · 392 阅读 · 0 评论 -
【POJ - 2186】Popular Cows (Tarjan缩点)
题干:Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M <= 50,000) ordered pairs of the form (A, B) that...原创 2019-03-12 10:01:38 · 204 阅读 · 0 评论 -
【计蒜客 - 程序设计竞赛】商业信息共享(Tarjan缩点)
题干:商业信息共享有N个公司,从每个公司都能单向地向另外一个公司分享最新商业信息,因为他们之间有着某种合作,你需要解决两个问题:现在有一个最新的商业信息,至少需要告诉多少个公司,使得所有的公司最终都能得到该信息。在原有基础上,至少需要再让多少对公司建立这种合作,使任意一个公司获得某个最新商业信息后,经过若干次分享,所有的公司最终都能得到该信息。输入格式第一行输入一个整数N...原创 2020-12-12 21:18:20 · 371 阅读 · 0 评论 -
【牛客 - 272D】Where are you(Tarjan求桥)
题干:小p和他的朋友约定好去游乐场游玩,但是他们到了游乐场后却互相找不到对方了。游乐场可以看做是一张n个点,m条道路的图,每条道路有边权wi,表示第一次经过该道路时的花费(第二次及以后经过时花费为0)。现在,小p要去找他的朋友,但他的朋友行踪很诡异,小p总是要遍历完这n个点才能找到他,同时小p希望总花费最小。找到朋友的方案可能不唯一(具体看样例解释),小p想知道在这所有的方案中,有多...原创 2019-03-12 14:49:16 · 304 阅读 · 0 评论 -
【Gym - 101986F】Pizza Delivery(Dijkstra最短路,建图方式,反向建图,Tarjan求桥,图论模板)
题干:题目大意:一个有向图,编号1~n的n个点,m条边,规定1为起点,2为终点,问对于每一条边,反转它的方向,最短路会不会发生改变,如果变短了,输出HAPPY,变长了或者到达不了了输出SAD,不变的话输出SOSO。解题报告:建三个图,正向图G1,反向图G2,对于G1的边(u,v),假如G1.d[u]+G2.[v]+w==G1.d[2],那么他就是最短路上的一条路径,用这些路径重...原创 2019-03-25 21:57:25 · 475 阅读 · 0 评论 -
【HDU - 4635】Strongly connected(缩点,新图性质,建图,Tarjan求强连通分量)
题干:Give 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 add these edges,...原创 2019-03-26 21:04:42 · 252 阅读 · 0 评论 -
【HDU - 1269】迷宫城堡 (tarjan算法模板)
题干:为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每个通道都是单向的,就是说若称某通道连通了A房间和B房间,只说明可以通过这个通道由A房间到达B房间,但并不说明通过它可以由B房间到达A房间。Gardon需要请你写个程序确认一下是否任意两个房间都是相互连通的,即:对于任意的i和j,至少存在一条路径可以从房间i...原创 2018-09-11 14:46:18 · 912 阅读 · 0 评论