DMPG '19 G5 - Hunting the White Whale

View as PDF

Submit solution


Points: 20 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

Subaru and Rem are hunting down the white whale. They currently have a list of N locations where the white whale has been rumoured to appear. There are N1 roads that connect every location to every other location. The ith of these typically sees ti travelers per day.

If the white whale travels along these roads, it continually travels along a single path that sees a total of K travelers per day, picked uniformly at random from all such paths. Doing so means that it will pass all locations that are on this path. Thus Rem asks Subaru N questions: if we wait at node 1,2,,N, what is the probability we will encounter the whale?

Constraints

For all subtasks:

0ti1000000

Subtask 1 [9%]

1N100

1K100

The network of roads forms the simplest possible line: For 1i<N, road i connects locations i and i+1.

Subtask 2 [12%]

1N1000

1K1000000

Subtask 3 [22%]

1N200000

1K100

Subtask 4 [57%]

1N200000

1K1000000

Input Specification

The first line of input will contain two space-separated integers, N and K.
The next N1 lines will each contain 3 integers: ai,bi,ti, indicating there is a road between locations ai and bi, with ti travelers per day.

Output Specification

You should output N lines, where each is the probability Rem and Subaru encounter the white whale, expressed as a fraction in lowest terms.

Sample Input

Copy
5 4
1 3 3
2 3 3
3 4 1
4 5 3

Sample Output

Copy
1 / 3
1 / 3
1 / 1
1 / 1
1 / 3

Explanation for Sample Output

The possible paths are:

  • 234
  • 134
  • 543

Locations 3 and 4 appear on all 3 paths, but locations 1, 2, and 5 only appear on a single path each.


Comments


  • 1
    spheniscine  commented 61 days ago edited

    Just in case it isn't clear from the problem statement:

    It may be possible that there are no paths that see a total of K travelers. [Perhaps the white whale is only a legend.] In this case, you should print 0 / 1 for all nodes.


  • 8
    discoverMe  commented on June 9, 2019, 4:07 a.m.

    what if a path has no chance? should it be 0 / 1?


    • 9
      Plasmatic  commented on June 9, 2019, 4:09 a.m.

      01 is a fraction in lowest terms