This page is still under construction.

Parts of this page are still being built. What you see may change.

Easter Holidays Ski Journey

Time limit1sMemory limit128 MB

Summary
For each resort, find a cycle that goes up by lifts then down by slopes, maximizing the ratio of total slope time to total lift time, and print it as a reduced fraction.
Level

Hard8 of 10

Topics
Binary search, Shortest path, Graph, Math
Solved
No attempts yet

Problem

Scandinavians love to ski during the Easter holidays at a large ski resort. The resort has many lifts that carry skiers upward and slopes of various difficulty that are skied downward.

Per is a beginner and is afraid of lifts, yet he still wants to ski as much as possible. He wants to plan a ski journey that:

  • starts at the bottom of some lift and returns to that same place;
  • consists of exactly two phases: first he rides one or more lifts upward, then he skis all the way back down to the starting place using slopes only;
  • is as little scary as possible, meaning the ratio of the time spent skiing on slopes to the time spent riding or waiting for lifts is as large as possible.

A resort has nn places, mm slopes, and kk lifts (2≤n≤10002 \le n \le 1000, 1≤m≤10001 \le m \le 1000, 1≤k≤10001 \le k \le 1000). Each slope leads from a higher place to a lower place, and each lift leads from a lower place to a higher place (a lift cannot be ridden downward). It is guaranteed that at least one valid ski journey exists in every resort.

Input

The first line contains the number of resorts to process. Each resort is described as follows. The first line contains three integers nn, mm, and kk. The next mm lines each describe a slope with three integers: its upper place, its lower place (places are numbered from 11 to nn), and the time to ski down the slope (at most 1000010000). The following kk lines each describe a lift with three integers: its lower place, its upper place, and the time to wait for and ride the lift up (at most 1000010000). No two places are connected by more than one lift or by more than one slope.

Output

For each resort, print on a single line the largest achievable scariness ratio as an irreducible fraction p/qp/q. This ratio is the total time spent on slopes divided by the total time spent riding or waiting for lifts.

Examples3

  1. Example 1

    Input
    1
    5 4 3
    1 3 12
    2 3 6
    3 4 9
    5 4 9
    4 5 12
    5 1 12
    4 2 18
    
    Expected output
    7/8
    
  2. Example 2

    Input
    1
    2 1 1
    2 1 10
    1 2 5
    
    Expected output
    2/1
    
  3. Example 3

    Input
    1
    3 3 3
    3 1 10
    3 2 6
    2 1 6
    1 2 3
    2 3 3
    1 3 4
    
    Expected output
    3/1