Sphere Online Judge

SPOJ Problem Set (classical)

3381. Highways

Problem code: HIGHWAYS

A number of cities are connected by a network of highways. Each highway is bidirectional and connects two cities, with a given travel time. What is the shortest time to get from a given city to another given city?

Input

The first line of input contains the number of test cases.

Each test case starts with a line containing the number of cities n (2 ≤ n ≤ 100000), the number of highways m (1 ≤ m ≤ 100000), the starting city and the ending city. Cities are numbered from 1 to n.

Then m lines follow, each describing one highway. The decription consists of the two distinct city numbers and the time in minutes to travel along the highway. The time will be between 1 and 1000.

Output

For each test case output a single line containing the minimum time it takes to get from the start to the destination. If no connection exists, output NONE.

Example

Input:
2
4 2 1 4
1 2 5
3 4 5
4 4 1 4
1 2 5
2 3 5
3 4 5
4 2 6


Output:
NONE
11


Added by:Daniel Gómez Didier
Date:2008-11-18
Time limit:3s
Source limit:50000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: ERL JS NODEJS PERL 6
Resource:Circuito de Maratones ACIS / REDIS

hide comments
2012-10-15 18:27:55 srikardurgi

forget about the mentioned range and use long long int for all variables
2012-08-20 03:33:46 Simón Murillo Gómez
Nothing special here. Just take care about the constraints

Last edit: 2012-08-20 03:53:28
2012-04-17 16:03:01 Swarn Avinash
My program is working fine on ideone...but giving SGVABRT here on spoj....==>http://ideone.com/GjL8y
2011-12-25 22:49:45 Jakub Šafin
Essam: think about it - it's not worth it
2011-03-01 22:44:40 multisystem
I didn't handle it and got AC.
2009-06-10 23:52:48 Essam AlNaggar
can the same route be entered twice with different values ?

Last edit: 2009-06-10 23:53:37
SPOJ © 2013 Sphere Research Labs. All Rights Reserved.