题目链接:http://poj.org/problem?id=2762 题意是 有t组样例,n个点m条有向边,取任意两个点u和v,问u能不能到v 或者v能不能到u,要是可以就输出Yes,否则输出No.注意一点,条件是或者!所以不是判断双连通图的问题. 我一开始没看到'or'这个条件,所以直接tarjan判断是否只有一个强连通分量,果断WA. 所以需要给原图缩点,用tarjan把图变成一个有向无环图,要是只有一个scc,那就直接输出Yes.那接下来讨论多个scc,要是新图中有两个及以上的点的入度为…
http://poj.org/problem?id=2762 Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12733   Accepted: 3286 Description In order to make their sons brave, Jiajia and Wind take them to a big cave. The cave has…
职务地址:id=2762">POJ 2762 先缩小点.进而推断网络拓扑结构是否每个号码1(排序我是想不出来这点的. .. ).由于假如有一层为2的话,那么从此之后这两个岔路的点就不可能从一点到还有一点的. 代码例如以下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include…
http://poj.org/problem?id=2762 题意:给出有向图,判断任意两个点u和v,是否可以从u到v或者从v到u. 思路: 判断图是否是单连通的. 首先来一遍强连通缩点,重新建立新图,接下来我们在新图中找入度为0的点,入度为0的点只能有1个,如果有多个那么这些个点肯定是不能相互到达的. 如果只有一个入度为0的点,走一遍dfs判断新图是否是单链,如果有分支,那么分支上的点肯定是不能相互到达的. #include<iostream> #include<algorithm&g…
题目链接: http://poj.org/problem?id=2762 Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14546   Accepted: 3837 Description In order to make their sons brave, Jiajia and Wind take them to a big cave. The cav…
id=2762">http://poj.org/problem?id=2762 Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14573   Accepted: 3849 Description In order to make their sons brave, Jiajia and Wind take them to a big cave. T…
Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17089   Accepted: 4590 Description 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…
Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15812   Accepted: 4194 Description 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…
Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17104   Accepted: 4594 Description 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,…
题目描述:为了让他们的儿子变得更勇敢些,Jiajia和Wind将他们带到一个大洞穴中.洞穴中有n个房间,有一些单向的通道连接某些房间.每次,Wind选择两个房间x和y,要求他们的一个儿子从一个房间走到另一个房间,这个儿子可以从x走到y,也可以从y走到x.Wind保证她布置的任务是可以完成的,但她确实不知道如何判断一个任务是否可以完成.为了使Wind下达任务更容易些,Jiajia决定找这样的一个洞穴,每对房间(设为x和y)都是相通(可以从x走到y,或者可以从y走到x)的.给定一个洞穴,你能告诉Ji…
题目大意: 为了锻炼自己的儿子 Jiajia 和Wind 把自己的儿子带入到一个洞穴内,洞穴有n个房间,洞穴的道路是单向的. 每一次Wind 选择两个房间  x 和 y,   让他的儿子从一个房间走到另一个房间,(要么从 x->y  或者 y->x), Wind承诺这个是一定可以走到的.但是他不知道如何判断这个 xy一定是互通的,现在给你一个洞穴,问随机给你两个洞穴的编号,是否是相通的. 题目分析:题目意思有点偏移,其实意思是(只要能从x->y  或者 y->x 这个都算是通的),…
Description 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 one of their little sons go from one to the o…
意甲冠军:给定一个有向图有m单向边缘.免费推断是否两点起来(a可以b要么b可以a或最多彼此),该请求 弱联通重量. 算法: 缩点求强连通分量.然后又一次建图.推断新图是否是一条单链,即不能分叉,假设分叉了就会存在不可达的情况. 怎么推断是否是单链呢? 就是每次入度为0的点都仅仅有一个,即每次队列里仅仅有一个点. (    o(╯□╰)o.... .好像已经是第二次用pair记录原图的点对,然后存pair的vector忘记清空导致wa来wa去! ) #include<cstdio> #inclu…
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 one of their little sons go from one to the other. The so…
Description 判断一个有向图是否对于任意两点 $x$,  $y$ 都有一条路径使$x - >y$或 $y - >x$ Solution 对于一个强联通分量内的点 都是可以互相到达的. 接下来我们考虑缩点后的DAG是否任意两点都有路径能使一点到达另一点. 然后我就不会了~~ 我们进行一遍拓扑排序, 如果过程中有超过一个点的入度为 $0$ ,那么就不符合条件(仔细想想好像还是对的 Code #include<cstdio> #include<cstring> #i…
Going from u to v or from v to u?   Description 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 one of th…
题意:判断一个有向图中的任意两点u.v,是否可以由其中一个点到达另一个点. 分析:这个问题转化以后就是:将该图强连通缩点后再判断其是否是单向连通的.缩点用Tarjan处理强连通分量. 有一个定理是这样的:一个有向图是单项连通的当且仅当其拓扑排序唯一.那么将这个子问题再转化为其缩点之后的图拓扑排序是否唯一. 如果一个有向图拓扑排序唯一,那么在根据入度求拓扑排序的过程中,不会有超过一个点在同一时刻同时为0. #include<stack> #include<stdio.h> #incl…
题意:(理解错了)在一个洞穴中有多个room,要求任意选两个room:u.v,都能保证u.v之间有通路,注意洞穴中的路是有向边.. 分析:强连通子图中的点必然两两之间可以互通,两个强连通子图之间有通路,必须在树上构成父子关系(不一定相邻),又两两之间有通路,即任意两个点u.v都存在父子关系——所有强连通子图构成一条链. 错误:tarjin初始化忘记更新scc_cnt=dfs_clock=0: #include<cstdio> #include<cstring> #include&l…
给出n个点,m条边,问是否任意两点u,v,是否满足u能够到达v,或者v能够到达u 自己写的时候以为缩一下点,然后再判断一下能不能拓扑排序就可以了 但是--wa--- 后来看了这篇题解 http://edward-mj.com/archives/27 按紫书上讲的,如果图中存在有向环,则不存在拓扑排序,反之则存在 所以上面这幅图是满足拓扑排序的 但是因为u,v的入度都为0,u,v之间不能到达 所以缩点完之后的图应该满足是一条长链才行 #include<cstdio> #include<cs…
题目链接:http://poj.org/problem?id=2762 思路:首先当然是要缩点建新图,由于题目要求是从u->v或从v->u连通,显然是要求单连通了,也就是要求一条长链了,最后只需判断链长是否等于新图顶点个数即可,至于如何求一条链长,直接dfs即可,注意点就是dfs是要从入度为0的顶点开始. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&g…
题目链接:http://poj.org/problem?id=2762 题意:给出一个有向图,判断任意的两个顶点(u,v)能否从u到达v,或v到达u,即单连通,输出Yes或No. 分析:对于同一个强连通分量而言,所有的点都是互达的,如果该有向图只有一个强连通分量,则肯定是Yes了: 若有多个强连通分量呢?判断两个不同的强连通分量的点u和v是否单连通,缩点后,建新图,用拓扑排序判断,删除点的时候若发现有大于2个点的入度为0,则u和v必定不能连通. AC代码: #include<cstdio> #…
Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15494   Accepted: 4100 Description 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…
Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14789   Accepted: 3915 Description 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…
这题搞了好久,先是拓扑排序这里没想到,一开始自己傻乎乎的跑去找每层出度为1的点,然后才想到能用拓扑排序来弄. 拓扑排序的时候也弄了挺久的,拓扑排序用的也不多. 题意:给一个图求是否从对于任意两个点能从v 到w 或者从w到v连通. 思路:单连通,先强连通缩点,若scnt为1,或者出度为零的点为0,直接输出YES,若出度为零的点大于1,则代表有分支输出NO.若出度为零的点为1,判断组成的树是否为单链,即没有分支,用拓扑排序即可. 代码: #include<iostream> #include<…
Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19234   Accepted: 5182 Description 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…
Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15755   Accepted: 4172 Description 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…
[题意]: 有N个房间,M条有向边,问能否毫无顾虑的随机选两个点x, y,使从①x到达y,或者,②从y到达x,一定至少有一条成立.注意是或者,不是且. [思路]: 先考虑,x->y或者y->x是什么意思,如果是且的话就简单了,就直接判断整个图是不是强联通图即可,但是这道题是或,那么可以随手画出一个DAG 比如1->3, 2->3 这样很明显是不行的,1,2没有联通,那么如果是这样1->2->3 就可以了,或者是1->2->3->1,这样也是可以的. 很…
Tarjan + TopsortTarjan 缩点Topsort 判断 Topsort 判断:在DAG中若初始状态下存在多于1个入度为0的点则说明这些 入度为0的点之间不会有路径可达若不存在入度为0的点,则状态为Yes 若只存在1个入度为0的点,将该点指出的边删除继续上述判断 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> , M = N * ; #d…
     Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K       Description 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 tim…
Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13040   Accepted: 3383 Description 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…