data-structures · intermediate · ~15 min
Reachability closure from one source.
int can_reach_all(const int *adj,int n,int src);
Return 1 if every vertex is reachable from src (directed), else 0.
adj n×n directed 0/1.
1 if src reaches all, else 0.
src reaches itself.
#include <stddef.h>
/* Return 1 if every node is reachable from src (directed graph), else 0. */
int can_reach_all(const int *adj,int n,int src){ (void)adj;(void)n;(void)src; return 1; }
Treating edges as undirected.
Single vertex → 1; any unreachable vertex → 0.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.