#P9758. [COCI 2022/2023 #3] Baltazar

[COCI 2022/2023 #3] Baltazar

Problem Description

Baltazar is getting ready to go on vacation. He is currently in Baltazargrad and wants to travel to Primosten. To get there, he needs to pass through many cities. There are nn cities connected by mm bidirectional roads. Baltazargrad is numbered 11, and Primosten is numbered nn.

Baltazar is not sure which route to take from Baltazargrad to Primosten, so he will use GPS, which will guide him along the shortest route.

But Baltazar really loves traveling, and he can use a magic potion on any road (even if he does not travel on it) to increase the road’s length by 22 kilometers. However, he can only use the potion once.

Soon he realizes that he must check into the Zora hotel in Primosten before noon. So he cannot increase the total length of the shortest path too much. He now wants to know how many roads he can use the potion on such that the length of the shortest path increases by exactly 11 kilometer.

Input Format

Multiple test cases.

The first line contains an integer tt, the number of test cases.

Then for each test case, the first line contains two integers n,mn,m, representing the number of cities and the number of roads between the cities.

The next mm lines each contain three integers ai,bi,wia_i,b_i,w_i, representing a road connecting cities ai,bia_i,b_i with length wiw_i. There is at most one road between any pair of cities.

It is guaranteed that all cities are connected. That is, for any pair of cities, there exists a path between them, but it may not be directly connected.

It is guaranteed that the sums of nn and mm over all test cases are each at most 300000300000.

Output Format

The first line outputs an integer cc, the number of roads on which Baltazar can use the magic potion.

The next line outputs cc integers, in increasing order of road index, listing all roads that satisfy the condition.

3
6 6
1 2 2
1 3 2
2 4 2
3 5 2
4 5 1
5 6 2
6 6
1 2 2
1 3 2
2 4 2
3 5 2
4 5 3
5 6 2
6 7
1 2 2
1 3 2
2 4 2
3 5 2
4 5 1
5 6 2
1 6 7
2
2 4
0

3
2 4 6

Hint

Sample Explanation

The cities and roads are shown in the figure. If Baltazar uses his magic potion on the second road (connecting cities 33 and 55), then the shortest distance between city 11 and city nn will increase by 11.

Constraints

Subtask Points Special Property
11 1515 n,m1000n,m \leq 1000
22 3030 There is a road between the start and the end, and its length is exactly 11 kilometer longer than the shortest route between the two cities.
33 6565 No special property.

For 100%100\% of the testdata, $1\le t \le 10000,2\leq n \leq 3\times10^5,1\le m\le \min(3\times 10^5,\dfrac{n\times (n-1)}{2}), 1\le a_i,b_i\le n,a_i\neq b_i,1\le w_i\le 10^9$.

This problem has a full score of 110110 points.

Translated by ChatGPT 5