data-structures · intermediate · ~15 min

Eccentricity (Dijkstra)

Reuse a shortest-path result.

Challenge

int dijkstra_eccentricity(const int *w,int n,int src);

Return the greatest shortest-path distance from src to any reachable vertex (0 if none reachable beyond src).

Input format

w n×n positive weights, 0=no edge.

Output format

Max finite shortest distance from src.

Constraints

Starter code

#include <stddef.h>
/* Max shortest-path distance from src to any reachable node (0 if none reachable beyond src). Weighted directed graph (0 = no edge). */
int dijkstra_eccentricity(const int *w,int n,int src){ (void)w;(void)n;(void)src; return 0; }

Common mistakes

Letting the ∞ of unreachable vertices count as the maximum.

Edge cases to handle

Isolated src → 0.

Background lessons

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.