data-structures · intermediate · ~15 min
Reachability via DFS.
int has_path(const int *adj,int n,int src,int dst);
Return 1 if dst is reachable from src via directed edges (a vertex reaches itself), else 0.
adj n×n directed; 0<=src,dst<n.
1 if reachable, else 0.
—
#include <stddef.h>
/* Return 1 if there is a directed path from src to dst (src==dst counts as reachable), else 0. */
int has_path(const int *adj,int n,int src,int dst){ (void)adj;(void)n;(void)src;(void)dst; return 0; }
Not handling src==dst; treating edges as undirected.
src==dst → 1; disconnected → 0.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.