Skip to content

Instantly share code, notes, and snippets.

@LukeWood
Created March 27, 2018 02:46
Show Gist options
  • Save LukeWood/47ce7cf832ffafa523378027e1dbab3f to your computer and use it in GitHub Desktop.
Save LukeWood/47ce7cf832ffafa523378027e1dbab3f to your computer and use it in GitHub Desktop.
def color_graph(ordering, adj_list):
coloring = [-1 for _ in ordering]
for node in ordering:
color = 0
used_colors = set([coloring[neighbor] for neighbor in adj_list[node]])
while color in used_colors:
color = color + 1
coloring[node] = color
return coloring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment