Public class Demo {
Static int [] hasFriend;
Static int [] [] Matrix;
Static int length;
Static int num=0;
Public static int findCircleNum (int [] [] M) {
HasFriend=new int [M.l ength];
The Arrays. The fill (hasFriend, 1);
Matrix=M;
Length=M.l ength;
for (int i=0; iIf (hasFriend [I]==1) {
The helper (I);
num++;
}
}
Return num.
}
Public static void helper (int I) {
HasFriend [I]=1;
For (int j=0; J & lt; Length; J++) {
If (Matrix [I] [j]==1 & amp; & The I!=j & amp; & HasFriend [j]==1) {
The helper (j);
}
}
}
Public static void main (String [] args) {
Int [] [] matrix={{0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0},
{0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
Int maxSubNumber=findCircleNum (matrix);
//this output is: maxSubNumber: 5
System. The out. Println (" maxSubNumber: "+ maxSubNumber);
}
}
But I want to get the biggest connected subgraph numerical, rather than unicom component number, what need how to rewrite?
StackOverflow address: https://stackoverflow.com/q/62610977/11433138