← All problemsSign in

Maximum Topological Sort

CodeChefRating 2304Open on judge ↗

Chef has a tree $G$ with $N$ nodes (numbered $1$ through $N$) and $N-1$ undirected edges. For each node $u$ in the tree, he can assign directions to the edges in such a way that $u$ is reachable from all the other nodes. Let $C_u$ be the number of valid [topological orderings](https://en.wikipedia.org/wiki/Topological_sorting) in the resulting directed acyclic graph. This way, Chef obtains $N$

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start