问题1451--Semiconnected

1451: Semiconnected

时间限制: 1Sec 内存限制:32 MB
提交:104 解决:26
[ 状态] [ 讨论版] [ 提交] [命题人: ]
题目描述

For a directed graph G = (V, E), if for all pairs of nodes u,v, u can always reach v or v can always reach u , then we call this a Semiconnected graph. Now you are given a directed graph, you should tell us whether it is a Semiconnected graph. If it is, output “yes”, or else“no”.

输入

There are several test cases, for each test case, there are two integers in the first line, n and m n(n<=10000) ,m(m<=50000) , means that there are n nodes and m edges in this graph. The nodes are numbered from 1 to n. Then m lines each with two integers u and v means there is an edge from u to v.

输出

For each test case, output “yes” if it is a Semiconnected graph, or else “no” instead.

样例输入 Copy
4 3 1 2 2 3 3 4 4 3 1 2 2 3 4 3
样例输出 Copy
yes no
来源/分类