This page is still under construction.

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

Best Edge

Interview

Time limit2sMemory limit1024 MB

Summary
Given a directed weighted graph with unique shortest paths, find the edges that lie on the most shortest paths between vertex pairs and print their numbers.
Level

Medium5 of 10

Topics
Shortest path, Graph, Tree, Heap
Solved
No attempts yet

Problem

You are given a directed graph with NN vertices and MM edges. The edges are numbered from 11 to MM in the order they appear in the input.

Soyeong thinks it is impressive when many pairs of vertices are connected by shortest paths. She gives each edge a score and awards the Best Edge prize to the edges with the highest score. An edge's score is computed as follows.

  • If a shortest path exists from vertex SS to vertex EE, every edge on that shortest path gets 1 point. The input only contains data where the shortest path is unique for every pair of vertices that has a path.
  • If no path exists from SS to EE, no edge gets a point for the pair (S,E)(S, E).
  • The final score of an edge is the sum of its points over all pairs (S,E)(S, E) with S≠ES \neq E and 1≤S,E≤N1 \le S, E \le N.

If several edges share the highest score, all of them receive the prize. Find the edges that receive the Best Edge prize.

Input

The first line contains two integers NN and MM, separated by a space. (2≤N≤2×103,1≤M≤min⁡(N×(N−1),5×103))(2 \le N \le 2 \times 10^3, 1 \le M \le \min(N \times (N-1), 5 \times 10^3))

Each of the next MM lines contains the start vertex uiu_i, the end vertex viv_i, and the length wiw_i of the ii-th edge, separated by spaces. No two edges connect the same pair of vertices, and no edge starts and ends at the same vertex. (1≤ui,vi≤N,ui≠vi,1≤wi≤109)(1 \le u_i, v_i \le N, u_i \neq v_i, 1 \le w_i \le 10^9)

Output

On the first line, print the number of edges that receive the prize. On the second line, print their numbers in increasing order, separated by spaces.

Examples3

  1. Example 1

    Input
    4 5
    4 3 5
    1 2 5
    3 4 3
    4 1 2
    2 1 4
    
    Expected output
    1
    4
    
  2. Example 2

    Input
    6 10
    1 5 1
    1 2 1
    5 1 1
    4 6 1
    6 4 1
    2 6 1
    1 3 1
    2 5 1
    5 2 1
    6 5 1
    
    Expected output
    2
    3 10
    
  3. Example 3

    Input
    2 2
    1 2 3
    2 1 4
    
    Expected output
    2
    1 2