Poj 3713 (determines whether an undirected graph is connected in three ways)

Source: Internet
Author: User

Transferring Sylla
Time limit:5000 Ms   Memory limit:65536 K
Total submissions:1160   Accepted:270

Description

After recapturing Sylla, the company plans to establish a new secure system, a transferring net! The new system is designed as follows:

The company staff chooseNCities around the nation which are connected by "Security tunnels" directly or indirectly. once a week, Sylla is to be transferred to another city through the tunnels. as general ordered, the transferring net must reach
A certain security level that there are at least 3 independent paths between any pair of citiesA,B. When General says the paths are independent, he means that the paths share onlyAAndBIn common.

Given a design of a transferring net, your work is to inspect whether it reaches such security level.

Input

The input consists of several test cases.
For each test case, the first line contains two integers,N≤0. 500 andM≤ 20000. indicating the number of cities and tunnels.
The followingMLines each contains two integersAAndB(0 ≤A, B<N), Indicating the cityAAnd CityBAre connected directly by a tunnel.

The input ends by two zeroes.

Output

For each test case output "yes" if it reaches such security level, "no" otherwise.

Sample Input

4 60 10 20 31 21 32 34 50 10 31 21 37 60 10 31 21 32 30 0

Sample output

 
Yesnono

Source

Poj founder monthly contest-2008.12.28, Dagger question: http://poj.org/problem? Id = 3713 analysis: There is no idea about tri-connectivity. Check that all the solutions of others are enumeration, remove a vertex, and determine whether there is a cut point or is connected. If there is a cut point or not, it is not a three-connection... It's strange. Time is so disgusting. I don't know how these hundreds of MS came from. Code :
# Include <cstdio> using namespace STD; const int Mm = 44444; const int Mn = 555; int T [mm], p [mm]; int H [Mn], dfn [Mn], low [Mn], Du [Mn]; int I, j, k, n, m, idx; bool DFS (INT U, int FA) {dfn [u] = low [u] = ++ idx; For (INT I = H [u], V, son = 0; I> = 0; I = P [I]) if (! Dfn [V = T [I]) {++ son; If (DFS (v, u) return 1; if (FA =-1 & Son> 1 | Fa! =-1 & dfn [u] <= low [v]) return 1; if (low [u]> low [v]) low [u] = low [v];} else if (V! = Fa & low [u]> dfn [v]) low [u] = dfn [v]; return 0;} bool Tarjan () {int I, J, K; for (I = 0; I <n; ++ I) if (Du [I] <3) return 0; for (I = 0; I <n; ++ I) {for (j = idx = 0; j <n; ++ J) dfn [J] = 0; dfn [I] = N + N; for (j = k = 0; j <n; ++ J) if (! Dfn [J]) {If (++ K> 1) return 0; If (DFS (J,-1) return 0 ;}return 1 ;}int main () {While (scanf ("% d", & N, & M), N + M) {for (I = k = 0; I <n; ++ I) H [I] =-1, Du [I] = 0; while (M --) {scanf ("% d", & I, & J ); T [k] = J, P [k] = H [I], H [I] = K ++; t [k] = I, P [k] = H [J], H [J] = K ++; ++ du [I], ++ du [J];} puts (Tarjan ()? "Yes": "no");} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.