Graph Theory37 sections · 1633 units
Open in Course

Town Judge - Graph Translation

From English to Graph

The trust relationships form a directed graph where each edge (a,b)(a, b) means person aa trusts person bb. The town judge is the vertex with in-degree n1n-1 and out-degree 00.

You can represent this using an array of in-degrees and out-degrees. Each trust pair increments one counter and decrements another.

This translation is the hard part. Once you see it is a degree-counting problem, the code writes itself.