"import java.util.*;
public class NetworkTopology {
public int topologytype(int N, int M, int[] input3, int[] input4) {
if (M != N - 1 && M != N) return -1; // Fast check for invalid cases
int[] degree = new int[N + 1]; // Degree of each node (1-based indexing)
// Build the degree array
for (int i = 0; i < M; i++) {
degree[input3[i]]++;
degree[input4[i]]++;
}
// Check for Bus Topology
boolean isBus = (M"
Alessandro R. - "import java.util.*;
public class NetworkTopology {
public int topologytype(int N, int M, int[] input3, int[] input4) {
if (M != N - 1 && M != N) return -1; // Fast check for invalid cases
int[] degree = new int[N + 1]; // Degree of each node (1-based indexing)
// Build the degree array
for (int i = 0; i < M; i++) {
degree[input3[i]]++;
degree[input4[i]]++;
}
// Check for Bus Topology
boolean isBus = (M"See full answer
Software Engineer
Data Structures & Algorithms
+1 more
🧠Want an expert answer to a question? Saving questions lets us know what content to make next.