回分類題庫
d310: (1052cp2_ex13) Is it a tree
出處:SPOJ

Difficulity : 1
Accepted : 25 Times | Submit :138 Times | Clicks : 420
Accepted : 18 Users | Submit : 26 Users | Accepted rate : 69%
Time Limit :10000 ms | Memory Limit : 64000 KBytes
題目加入時間 : 2017-06-09 14:32

Content :

You are given an unweighted, undirected graph. Write a program to check if it's a tree topology.

Input :

The first line of the input file contains two integers N and M --- number of nodes and number of edges in the graph (0 < N <= 10000, 0 <= M <= 20000). Next M lines contain M edges of that graph --- Each line contains a pair (uv) means there is an edge between node u and node v (1 <= u,v <= N).

Output :

Print YES if the given graph is a tree, otherwise print NO.

Sample Input :

3 2
1 2
2 3

Sample Output :

YES

Hint :

dfs

Author :

SPOJ (管理員:cp2ta)

  Solve it!   Status Forum (0)

C++
C
JAVA
85536. cp2ta (8 ms , 391KB)
85641. nccucs105703047 (3 ms , 207KB)
85686. nccucs105703008 (4 ms , 200KB)
85687. nccucs105703008 (5 ms , 198KB)
85656. nccucs105703050 (5 ms , 255KB)
85717. nccucs105703027 (6 ms , 262KB)
沒有解題記錄

執行時間會受很多因素影響因此僅供參考,主機等級請看這裡