data-structures · intermediate · ~15 min
The classic 'celebrity' property.
int has_universal_sink(const int *adj,int n);
A universal sink is a vertex with out-degree 0 that every other vertex points to. Return 1 if one exists, else 0.
adj n×n directed 0/1.
1 if a sink exists, else 0.
Single vertex is a sink.
#include <stddef.h>
/* Return 1 if the directed graph has a universal sink: a node with out-degree 0 that every OTHER node points to. */
int has_universal_sink(const int *adj,int n){ (void)adj;(void)n; return 0; }
Forgetting the sink must have no outgoing edges, or that all others must point to it.
Single vertex → 1; a cycle → 0.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.