It's strange to find a cut point in poj 1144 ....

Source: Internet
Author: User

It is easy to calculate the number of cut points.

Difficult in some details

It is unclear why dfn is set to 1 at the beginning. Why is it wrong?

IncorrectCode

View code

# Include <stdio. h>
# Include < String . H>
Int N, son, ans;
Int Map [ 1000 ] [ 1000 ];
Int Dfn [ 1000 ], Low [ 1000 ];
Int Vis [ 1000 ];
Int Tdfn;
Int Flag [ 1000 ];
Int Min ( Int A, Int B ){
Return A <B? A: B;
}
Void DFS ( Int U ){
Int V;
For (V = 1 ; V <= N; V ++ ){
If (Map [u] [v]) {
If (! Vis [v]) {
Vis [v] = 1 ;
Tdfn ++;
Low [v] = dfn [v] = tdfn;
DFS (v ); // To get low [v];
Low [u] = min (low [u], low [v]);
If (Low [v]> = dfn [u]) {
If (U = 1 ) Son ++;
Else Flag [u] = 1 ;
}
}
Else Low [u] = min (dfn [v], low [u]);
}
}
}
Void Init (){
Tdfn = 1 ; Ans =0 ; Vis [ 1 ] = 1 ; Son = 0 ;
Memset (map, 0 , Sizeof (MAP ));
Memset (VIS, 0 , Sizeof (VIS ));
Memset (flag, 0 , Sizeof (FLAG ));
Dfn [ 1 ] = Low [1 ] = 1 ;
}
Int A [ 1000 ];
Int Main (){
Int I = 0 , J;
Int U, V;
Char Ch;
While (Scanf ( " % D " , & N), n ){
Init ();
While (Scanf ( " % D " , & U), U)
While (Getchar ()! = ' \ N ' )
{
Scanf ( " % D " , & V );
Map [u] [v] = map [v] [u] = 1 ;
}
DFS ( 1 ); Ans = 0 ;
If (Son> = 2 ) Ans ++;
For (I = 1 ; I <= N; I ++) ans + = Flag [I];
Printf ( " % D \ n " , ANS );
}
Return 0 ;
}

Real code

View code

# Include <stdio. h>
# Include < String . H>
Int N, son, ans;
Int Map [ 110 ] [ 110 ];
Int Dfn [ 110 ], Low [ 110 ];
Int Vis [ 110 ];
Int Tdfn;
Int Flag [ 110 ];
Int Min ( Int A, Int B ){
Return A <B? A: B;
}
Void DFS ( Int U ){
Int V; dfn [u] = low [u] = ++ tdfn;
For (V = 1 ; V <= N; V ++ ){
If (Map [u] [v]) {
If (! Dfn [v]) {
DFS (v ); // To get low [v];
Low [u] = min (low [u], low [v]);
If (Low [v]> = dfn [u]) {
If (U = 1 ) Son ++;
Else Flag [u] = 1 ;
}
}
Else Low [u] = min (dfn [v], low [u]);
}
}
}
Void Init (){
Tdfn = 0 ; Son = 0 ; Ans = 0 ;
Memset (map, 0 ,Sizeof (MAP ));
Memset (flag, 0 , Sizeof (FLAG ));
Memset (dfn, 0 , Sizeof (Dfn ));
}
Int A [ 110 ];
Int Main (){
Int I = 0 , J;
Int U, V;
While (Scanf ( " % D " , & N), n ){
Init ();
While (Scanf ( " % D " , & U), U)
While (Getchar ()! = ' \ N ' )
{
Scanf ( " % D " , & V );
Map [u] [v] = map [v] [u] = 1 ;
}
DFS ( 1 );
If (Son> = 2 ) Ans ++;
For (I = 2 ; I <= N; I ++) ans + = Flag [I];
Printf ( " % D \ n " , ANS );
}
Return 0 ;
}

Name of the adjacent table

# Include <stdio. h> # include <string. h >#include <iostream >#include <vector> using namespace STD; vector <int> list [1000]; int low [1000], DEP [1000]; int Col [1000]; int N, son, ans; int flag [1000]; int min (int A, int B) {return a <B? A: B;} void DFS (INT U, int FA, int t) {Col [u] = 1; Dep [u] = low [u] = T; int Tol = 0; int I, V; for (I = 0; I <list [u]. size (); I ++) {v = list [u] [I]; If (COL [v] = 2) continue; if (COL [v] = 0) {DFS (v, U, t + 1); Tol ++; low [u] = min (low [u], low [v]); If (u = 1 & tol> 1 | low [v]> = Dep [u] & U! = 1) {flag [u] = 1 ;}} else if (COL [v] = 1 & V! = FA) {LOW [u] = min (low [u], DEP [v]) ;}} void Init () {son = 0; ans = 0; memset (flag, 0, sizeof (FLAG); memset (DEP, 0, sizeof (DEP); memset (COL, 0, sizeof (COL ));} int main () {int I = 0, J; int U, V; while (scanf ("% d", & N), n) {Init (); for (I = 0; I <= N; I ++) list [I]. clear (); While (scanf ("% d", & U), u) while (getchar ()! = '\ N') {scanf ("% d", & V); list [u]. push_back (V); list [v]. push_back (U);} DFS (1,-1, 1); for (I = 1; I <= N; I ++) ans + = Flag [I]; printf ("% d \ n", ANS);} 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.