QTGIFT3 - Christmas is coming

Christmas will come next month, so DB is planning to give TN a wonderful gift.

The city that DB and TN are living has n intersections. Each direct connections between 2 intersections has its length. In the Christmas night, TN will wait at the t-th intersection, and DB will start from the s-th intersection go through some connections, to the date place.

Of course DB doesn’t want to make TN wait for long time, so he will choose the shortest path. He also want to know how many different shortest paths from s to t (there is at least one path).

Because the number of intersections and connections are too large, DB can’t calculate these himself, so he need you help.

Input

  • First line : 3 positive integers, n, s and t (2 ≤ n ≤ 105, 1 ≤ s, t ≤ n, s ≠ t)
  • n lines : the i-th line contains 3 positive integers l, r, w, means there are direct connections from i to l, i to l + 1, ... i to r, each has length w (1 ≤ l ≤ r ≤ n, w ≤ 106)

Output

  • Two positive integers, length of the shortest path, and number of the shortest paths (modulo 1015), separated by a space

Example

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

Output:
8 2

Detais: the two shortest paths are (1, 2, 4) and (1, 3, 4)


Added by:Kata
Date:2014-11-25
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own Problem

hide comments
2015-01-05 05:30:25 Kata
Thanks :D. I glad you enjoyed it.
2014-12-23 18:02:54 LeppyR64
Interesting problem. I can't get past the O(n^2) graph density.
2014-12-23 16:11:24 Francky
Please upload the image on spoj system.

(Kata) : Uploaded.

(Francky) : Many thanks.

Last edit: 2014-12-23 16:27:28
2014-12-23 16:11:24 Kata
Yes. You can see the image. Problem edited.

Last edit: 2014-12-23 14:09:58
2014-12-23 16:11:24 રચિત (Rachit)
Are the connections directed?
2014-12-23 16:11:24 Jasmeet Singh
Tried with Dijkstra with Min-Heap and Dijkstra's without Min-Heap (Find minimum by iterating over distance array) .. Both give TLE .. any ideas ?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.