Edge Destruction
Tag(s):

## Algorithms, Graph Theory, Medium

Problem
Editorial
Analytics

Given a graph having N vertices and M bidirectional edges, with each edge having some length and some destruction cost. You have to increase the length of the shortest path between vertex 1 and vertex N, for that you can destroy some edges. Find the minimum cost of doing it.

Input Format:
First line consists of two space separated integers denoting N and M.
Following M lines consists of four space separated integers $X \; Y \; D \; C$ denoting that there is an edge between vertex X and Y having length D and destruction cost C.

Output Format:

Constraints:
$2 \le N \le 1000$
$1 \le M \le 4 \times 10^5$
$1 \le X, Y \le N$
$1 \le D, C \le 1000000$

SAMPLE INPUT
4 6
1 2 4 1
1 3 8 6
1 4 1 8
2 3 8 8
2 4 5 7
3 4 7 5

SAMPLE OUTPUT
8

Explanation

Currently the shortest path between 1 and 4 is of length 1, so we delete this vertex at a cost of 8, so that the length of shortest path increases to 9.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in

Challenge Name

HackerEarth Collegiate Cup - Mirror Round

OTHER PROBLEMS OF THIS CHALLENGE
• Basic Programming > Bit Manipulation
• Algorithms > Dynamic Programming
• Algorithms > Sorting
• Algorithms > Dynamic Programming
• Algorithms > Graphs
• Algorithms > Graphs
• Data Structures > Advanced Data Structures
• Math > Linear Algebra
• Algorithms > Searching
• Algorithms > Dynamic Programming