ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1080. Map Coloring

Hint
Posted by Kirill Teplinskiy (USTU-RTF) 10 Sep 2008 21:43
1). Use depth-first search
2). Use local variable for color in dfs procedure
Re: Hint
Posted by Anton 16 Dec 2011 10:55
dfs is enough, but it's better to store graph using compliance matrix, so keeping it in this way, your dfs will visit all nodes (1) and only when current node is already colored (2). If some of node, that we can go fro current is already colored and it has the same color, so -1 should be returned.