n = 5 d = {'33956':['27538','84925'],'79731':['91415','25288'],'25288':['33956']} def findmax(d): res = [] visited = [] for x in d: if x in visited: continue visited.append(x) tem = d[x].copy() rt = 0 while tem: print(tem) ...