data-structures · intermediate · ~15 min
Level sizes in a BFS tree.
int bfs_count_at_distance(const int *adj,int n,int src,int d);
Return how many vertices are at exactly BFS distance d from src (d==0 counts just src).
adj n×n directed; d>=0.
Count of vertices at distance d.
—
#include <stddef.h>
/* Number of nodes whose shortest-path (BFS) distance from src is exactly d. */
int bfs_count_at_distance(const int *adj,int n,int src,int d){ (void)adj;(void)n;(void)src;(void)d; return 0; }
Counting distance ≤ d instead of exactly d.
d larger than the graph's radius → 0; d==0 → 1.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.