Hacking

Interview

Time limit2sMemory limit256 MB

Summary
Starting from the hacked computer, count reachable computers through dependency edges and report the longest infection time.
Level

Medium4 of 10

Topics
Shortest path, Graph, Heap
Solved
No attempts yet

Problem

A hacker compromises one computer in a network. If computer a depends on computer b, then once b is infected, computer a becomes infected after s seconds.

Given the hacked computer and all dependencies, report how many computers become infected and how long until the last infection.

Input

The first line contains TT test cases (T≤100T \le 100). Each test case starts with nn, dd, and cc, followed by dd lines with aa, bb, and ss meaning a depends on b.

Output

For each test case, print the number of infected computers and the time of the last infection.

Examples1

  1. Example 1

    Input
    2
    3 2 2
    2 1 5
    3 2 5
    3 3 1
    2 1 2
    3 1 8
    3 2 4
    
    Expected output
    2 5
    3 6