Help (graph problem)

Revision en1, by jerseyguy, 2022-11-12 12:47:04

question :

Given n cities and m roads b/w them. Each road is represented as [L,R,X] L is the starting city, R — the ending city, and X the cost.
Also for all roads L<R . If there is a road from city L to R with cost X then one can travel b/w any two cities that lie b/w L and R with cost X.

Find the minimum cost to travel from 1 to N.

T<=10
N,M <= 1e5
L,R<=N
X<=1e6

My approach : sorting and priority queue , but it gave WA

sample:
2
4 1
1 3 10
4 3
1 4 10
1 2 5
2 4 3

op:
-1
8

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English jerseyguy 2022-11-13 09:10:39 1
en2 English jerseyguy 2022-11-12 12:50:28 11 Tiny change: '/w L and R with cost' -> '/w L and R(inclusive) with cost'
en1 English jerseyguy 2022-11-12 12:47:04 575 Initial revision (published)