Skip to content

Commit 6afd494

Browse files
authored
Create Cut Bridge or Cur Edges
1 parent 53c6df3 commit 6afd494

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Cut Bridge or Cur Edges

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
public class Main {
2+
3+
static int[] low,dfsnum;
4+
static int num=1;
5+
static int noOfVertices;
6+
7+
public static void main(String[] args) {
8+
9+
noOfVertices=7;
10+
11+
int[][] adjMatrix=new int[][]{
12+
{0,1,0,1,0,0,0},
13+
{1,0,1,0,0,0,0},
14+
{0,1,0,1,0,0,1},
15+
{1,0,1,0,0,1,0},
16+
{0,0,0,0,0,1,0},
17+
{0,0,0,1,1,0,0},
18+
{0,0,1,0,0,0,0}
19+
};
20+
low=new int[noOfVertices];
21+
dfsnum=new int[noOfVertices];
22+
23+
System.out.println("Cut Edges / Cut Bridges are: ");
24+
for (int i = 0; i < noOfVertices; i++) {
25+
if (dfsnum[i] == 0) {
26+
cutVertices(adjMatrix,i,i);
27+
}
28+
}
29+
}
30+
31+
static void cutVertices(int[][] adjMatrix, int vertex,int pre){
32+
low[vertex]=dfsnum[vertex]=num++;
33+
34+
for(int v=0;v<noOfVertices;v++){
35+
if(v==pre) continue;
36+
if(adjMatrix[vertex][v]==1) {
37+
if(dfsnum[v]!=0){
38+
low[vertex]=Math.min(low[vertex],dfsnum[v]);
39+
}
40+
else{
41+
cutVertices(adjMatrix,v,vertex);
42+
low[vertex] = Math.min(low[vertex],low[v]);
43+
if(low[v]>dfsnum[vertex]){
44+
System.out.println((char)('A'+vertex) +" ----- "+(char)('A'+v));
45+
}
46+
}
47+
}
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)