Login

All Problems

Problem title

Difficulty

Avg time to solve

Path to the nearest service station

Moderate

15 mins

Maximum number in K swaps

Hard

15 mins

Remove maximum edges

Easy

15 mins

String Without 000 Or 111

Easy

15 mins

Sibling Nodes

Moderate

20 mins

Remove 9

Easy

15 mins

Matching Prefix

Moderate

--

Longest Absolute File Path

Moderate

10 mins

Power Of 2

Moderate

20 mins

Bellman Ford

Moderate

30 mins

Problem

Submissions

2

Avg. time to solve

30 min

Success Rate

70%

Problem Statement

```
3 3 1 3
1 2 2
1 3 2
2 3 -1
In the above graph, the length of the shortest path between vertex 1 and vertex 3 is 1->2->3 with a cost of 2 - 1 = 1.
```

```
It's guaranteed that the graph doesn't contain self-loops and multiple edges. Also the graph does not contain negative weight cycles.
```

```
The first line of input contains an integer ‘T’ denoting the number of test cases. Then each test case follows.
The first line of each test case contains four single space-separated integers ‘N’, ‘M’ , ‘src’ and ‘dest’ denoting the number of vertices, the number of edges in the directed graph the source vertex and the destination vertex respectively.
The next ‘M’ lines each contain three single space-separated integers ‘u’, ‘v’, and ‘w’, denoting an edge from vertex ‘u’ to vertex ‘v’, having weight ‘w’.
```

```
For each test case, return an integer denoting the length of the shortest path from ‘src’ to ‘dest’. If no path is possible return 10^9.
```

```
You do not need to print anything, it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 10
1 <= N <= 50
1 <= M <= 300
1 <= src, dest <= N
1 <= u,v <= N
-10^5 <= w <= 10^5
Time Limit: 1 sec
```

```
1
4 4 1 4
1 2 4
1 3 3
2 4 7
3 4 -2
```

```
1
```

```
The optimal path from source vertex 1 to destination vertex 4 is 1->3->4 with a cost of 3 - 2 = 1.
```

```
1
2 1 1 2
2 1 3
```

```
1000000000
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code