Network UVA - 315 no point looking to cut map

Meaning of the questions:

To give you an undirected graph, you need to find out where there are several cut points

 

Code:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<iostream>
 4 #include<algorithm>
 5 #include<queue>
 6 using namespace std;
 7 const int maxn=105;
 8 int cnt,head[maxn],n,dfn[maxn],low[maxn],num,qua,root,iscut[maxn];
 9 struct edge
10 {
11     int u,v,next;
12 }e[maxn*maxn];
13 void add_edge(int x,int y)
14 {
15     e[cnt].u=x;
16     e[cnt].v=y;
17     e[cnt].next=head[x];
18     head[x]=cnt++;
19 }
20 void tarjan(int x)
21 {
22     dfn[x]=low[x]=++num;
23     int flag=0;
24     for(int i=head[x];i!=-1;i=e[i].next)
25     {
26         int  to=e[i].v;
27         if(!DFN [to])
 28          {
 29              Tarjan (to);
 30              Low [X] = min (Low [X], Low [to]);
 31 is              IF (Low [to]> = DFN [X])
 32              {
 33 is                  In Flag ++ ;
 34 is                  IF (X = the root || in Flag>! . 1 ) iscut [X] = . 1 , qua ++ ;
 35              }   // a cut point may repeatedly experienced iscut [x] = 1, so the value is not cut inside qua points head 
36          }
 37 [          the else Low [X] = min (DFN [to], Low [X]);
 38 is      }
 39  }
 40  int main()
41 {
42     while(~scanf("%d",&n) && n)
43     {
44         cnt=num=qua=0;
45         memset(iscut,0,sizeof(iscut));
46         memset(head,-1,sizeof(head));
47         memset(dfn,0,sizeof(dfn));
48         memset(low,0,sizeof(low));
49         int x,y;
50         char ch;
51         while(~scanf("%d",&x) && x)
52         {
53             while(~scanf("%d",&y))
54             {
55                 scanf("%c",&ch);
56                 add_edge(x,y);
57                 add_edge(y,x);
58                 if(ch=='\n'){
59                     break;
60                 }
61             }
62         }
63 //        for(int i=0;i<cnt;++i)
64 //        {
65 //            printf("%d %d\n",e[i].u,e[i].v);
66 //
67 //        }
68         for(int i=1;i<=n;++i)
69         {
70             if(!dfn[i])
71             {
72                 //printf("**\n");
73                 root=i;
74                 tarjan(i);
75             }
76         }
77         int ans=0;
78         for(int i=1;i<=n;++i)
79             if(iscut[i]) ++ans;
80         printf("%d\n",ans);
81     }
82     return 0;
83 }

 

Guess you like

Origin www.cnblogs.com/kongbursi-2292702937/p/11665109.html