v <- c(
1, 1, 0, 1,
1, 1, 0, 0,
1, 0, 0, 0,
0, 0, 0, 1,
0, 0, 1, 1,
1, 0, 0, 0,
0, 0, 0, 0)
x <- matrix(v, ncol=4, byrow=TRUE)
x
countConnected(x)
if (FALSE) {
# will break because of connection at a vertex
v <- c(
1, 1, 0, 1,
1, 1, 0, 0,
1, 0, 0, 0,
0, 0, 0, 1,
0, 0, 1, 1,
1, 0, 0, 0,
0, 1, 0, 0)
x <- matrix(v, ncol=4, byrow=TRUE)
x
countConnected(x)
}
Run the code above in your browser using DataLab