def tree_csp_solver(csp):
n = len(csp.vars)<EOL>assignment = {}<EOL>root = csp.vars[<NUM_LIT:0>]<EOL>X, parent = topological_sort(csp.vars, root)<EOL>for Xj in reversed(X):<EOL><INDENT>if not make_arc_consistent(parent[Xj], Xj, csp):<EOL><INDENT>return None<EOL><DEDENT><DEDENT>for Xi in X:<EOL><INDENT>if not csp.curr_domains[Xi]:<EOL><INDENT>return None<EOL><DEDENT>assignment[Xi] = csp.curr_domains[Xi][<NUM_LIT:0>]<EOL><DEDENT>return assignment<EOL>
[Fig. 6.11]