Approach hintTry it first, then revealHide
Let dp[s][f] count paths of total weight s, where f records whether an edge of weight at least d has appeared yet. Each step appends an edge of weight 1 to k and updates f; work modulo 10^9 + 7.