CRITICAL
A team of engineers is working on improving the road network of a country. They are specifically interested in the roads through which one can reach from the capital to the other cities of the country. In the country, there are N cities and M roads (one-way) through which one can reach from the capital to all other cities (either directly or via intermediate cities). Each road connecting a city to a city y has a positive integer length w(x, y).
The engineers consider a road to be important when reducing its length by one unit results in a corresponding decrease in the distance from the capital to some other city, and very important when increasing its length by one unit results in a corresponding increase in the distance from the capital to some other city. They want to calculate how many roads are important and how many are very important in the road network of the country.
Write a program to calculate the number of important roads and the number of very important roads.
Input
The first line of input will contain two integers N and M: the number of cities and the number of roads. Each of the next M lines of input will contain three integers , , and w(x, y), separated in pairs by a single space, indicating that there is a road of length w(x, y) connecting city to city .
Consider that the cities are numbered from 1 to N, the capital is city 1, all roads are one-way, and each road appears only once. Also, assume that from the capital, it is always possible to reach all other cities.
Output
The output should consist of a single line containing two natural numbers separated by a single space: the number of important roads and the number of very important roads.
Constraints
2 N 40.000
N – 1 M 400.000
1 w(x, y) 1.000
Execution time limit: 1 sec.
Memory limit: 64 MB.
Example of Input - Output
STDIN (critical.in)
5 9
1 2 1
1 3 2
1 4 9
1 5 8
2 3 1
2 4 5
2 5 7
3 5 2
5 4 2
STDOUT (critical.out)
6 2
Explanation of the example: The roads (1, 2), (1, 3), (2, 3), (2, 4), (3, 5), and (5, 4) are important (6 roads in total). For example, reducing the length of road (1, 2) from 1 to 0 decreases the distance from the capital to city 2 from 1 to 0. Similarly, reducing the length of road (2, 3) from 1 to 0 decreases the distance from the capital to city 3 from 2 to 1. The same reasoning applies to roads (2, 3), (2, 4), (3, 5), and (5, 4).
The roads (1, 2) and (3, 5) are very important (2 roads in total). For example, increasing the length of road (1, 2) from 1 to 2 increases the distance from the capital to city 2 from 1 to 2. Similarly, increasing the length of road (3, 5) from 2 to 3 increases the distance from the capital to city 5 from 4 to 5.
Comments