Please explain what is wrong with this code for Google Kickstart 2020 Round 
C Problem 2 Stable Wall

def dfs(visited, graph, node):
if node not in visited:
print(node, end = "")
visited.add(node)
for neighbour in graph[node]:
dfs(visited, graph, neighbour)

for case in range(1, int(input()) +1):
visited = set()
flag= 0
r,c = [int(x) for x in input().split()]
mat = []
char = []
char = set()
for i in range(r):
li = list(input())
mat.append(li)
for i in li:
char.add(i)
#print(char)
#print(mat)
pairs = []
pairs = set()
for i in range(r-1):
for j in range(c):
if mat[i][j] != mat[i+1][j] and (mat[i][j], mat[i+1][j]) not in pairs:
pairs.add((mat[i][j], mat[i+1][j]))
if (mat[i+1][j], mat[i][j]) in pairs:
print("Case #{}: -1".format(case))
flag = 1
break
if flag == 1:
break
if flag == 0:
#print(pairs)
with_edge = []
adj = {}
for i in char:
adj[i] = []
for pair in pairs:
adj[pair[1]].append(pair[0])
with_edge.append(pair[0])
#print(adj)
for i in char:
if i in char and i not in with_edge:
start = i
#print(start)
print("Case #{}: ".format(case), end = "")
dfs(visited, adj, start)
print()

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/9028bc74-e18a-4671-a765-56fba68589b2%40googlegroups.com.

Reply via email to