# https://www.codeconvert.ai/pascal-to-python-converter import sys def euler_path_cycle(n, a): # Calculate the degree of each node g = [0] * n for i in range(n): for j in range(n): g[i] += a[i][j] # Print the adjacency matrix print("Adjacency matrix:") for row in a: print(" ".join(map(str, row))) print() # Print the degree of each node print("Node degrees:") for degree in g: print(degree) print() # Decide based on the Euler theorem odd_count = 0 for degree in g: if degree % 2 != 0: odd_count += 1 if odd_count == 0 or odd_count == 2: if odd_count == 0: print("Each node has an even degree,") print("therefore, the graph has an Euler circuit.") else: print("The degree of exactly two nodes is odd,") print("therefore, the graph has an Euler path,") print("but no Euler circuit.") else: if odd_count == 1: print("Since", odd_count, "node has an odd degree,") else: print("Since", odd_count, "nodes have an odd degree,") print("the graph has neither an Euler circuit nor an Euler path.") if __name__ == "__main__": print("Enter the number of nodes (maximum 20):") n = int(input()) # Input the adjacency matrix a = [] for i in range(n): row = [] for j in range(n): print(f"a({i+1},{j+1}) = ", end="") row.append(int(input())) a.append(row) euler_path_cycle(n, a)