Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- v = input("enter the vertices: ")
- v = [x.strip(' ') for x in v.split(',')]
- e = input("enter the edges: ")
- e = [x.strip(' ') for x in e.split(',')]
- graph = list(tuple(x.split('-')) for x in e)
- def eulerian_trail(graph):
- first_vertex = graph[0][0]
- adj = {}
- trail = []
- for edge in graph:
- a,b = edge
- if a not in adj:
- adj[a] = []
- if b not in adj:
- adj[b] = []
- adj[a].append(b)
- adj[b].append(a)
- for vertex in v:
- c = vertex
- if c == first_vertex:
- trail.append(c)
- trail.extend(adj[c][0])
- adj.pop([c][0],0)
- if c in trail:
- if adj[c][0] != trail[-1]:
- trail.extend(adj[c][0])
- adj.pop([c][0],0)
- else:
- trail.extend(adj[c][1])
- adj.pop([c][1],0)
- return trail,adj
- eulerian_trail(graph)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement