Tap here to switch tabs
Problem
Submissions

Problem: Shortest Distance After Road Addition Queries I

Try to solve the Shortest Distance After Road Addition Queries I problem.

Statement

You are given an integer n denoting the number of cities numbered from 00 to n−1n - 1.

Initially, there is a directed road from city i to city i+1i + 1 for every 0≤i<n−10 \leq i < n - 1.

You are also given a 22D integer array queries, where each queries[i] =[ui,vi]= [u_i, v_i] represents the addition of a new directed road from city u_i to city v_i.

After adding each road, determine the length of the shortest path from city 00 to city n−1n - 1.

Return an array ans where ans[i] is the length of the shortest path from city 00 to city n−1n - 1 after processing the first i+1i + 1 queries.

Constraints:

  • 3≤3 \leq n ≤500\leq 500

  • 1≤1 \leq queries.length ≤500\leq 500

  • queries[i].length =2= 2

  • 0≤0 \leq queries[i][0] << queries[i][1] << n

  • 1<1 < queries[i][1] −- queries[i][0]

  • There are no repeated roads among the queries.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Shortest Distance After Road Addition Queries I

Try to solve the Shortest Distance After Road Addition Queries I problem.

Statement

You are given an integer n denoting the number of cities numbered from 00 to n−1n - 1.

Initially, there is a directed road from city i to city i+1i + 1 for every 0≤i<n−10 \leq i < n - 1.

You are also given a 22D integer array queries, where each queries[i] =[ui,vi]= [u_i, v_i] represents the addition of a new directed road from city u_i to city v_i.

After adding each road, determine the length of the shortest path from city 00 to city n−1n - 1.

Return an array ans where ans[i] is the length of the shortest path from city 00 to city n−1n - 1 after processing the first i+1i + 1 queries.

Constraints:

  • 3≤3 \leq n ≤500\leq 500

  • 1≤1 \leq queries.length ≤500\leq 500

  • queries[i].length =2= 2

  • 0≤0 \leq queries[i][0] << queries[i][1] << n

  • 1<1 < queries[i][1] −- queries[i][0]

  • There are no repeated roads among the queries.