Floyd-Warshall

아직 제출이 없습니다시간 제한5초메모리 제한256 MB

문제

Radewoosh has nn-vertex directed weighted graph. He needs to determine distances between all pairs of vertices. He decided to use Floyd-Warshall's algorithm for that.

Correct implementation of Floyd-Warshall's algorithm.

  1. MM -- n×nn \times n matrix. Initially: M_i,j={ 0,if i=jw_i,j,if there exists an edge from i to j with weight w_i,jotherwise M\_{i,j} = \begin{cases}  0, & \text{if } i = j \\\  w\_{i,j}, & \text{if there exists an edge from $i$ to $j$ with weight $w\_{i,j}$} \\\  \infty & \text{otherwise}  \end{cases}
  2. for xx = 1,2,3,,n1, 2, 3, \dots, n do
  3.     for yy = 1,2,3,,n1, 2, 3, \dots, n do
  4.         for zz = 1,2,3,,n1, 2, 3, \dots, n do
  5.             M_y,zmin(M_y,z,M_y,x+M_x,z)M\_{y,z} \leftarrow\min(M\_{y,z}, M\_{y,x} + M\_{x,z})

Unfortunately Radewoosh messed up loops order and his algorithm became incorrect!

Incorrect implementation of Floyd-Warshall's algorithm.

  1. MM -- n×nn \times n matrix defined as above.
  2. for yy = 1,2,3,,n1, 2, 3, \dots, n do
  3.     for zz = 1,2,3,,n1, 2, 3, \dots, n do
  4.         for xx = 1,2,3,,n1, 2, 3, \dots, n do
  5.             M_y,zmin(M_y,z,M_y,x+M_x,z)M\_{y,z} \leftarrow\min(M\_{y,z}, M\_{y,x} + M\_{x,z})

How many distances determined by Radewoosh's algorithm will be incorrect?

입력

The first line of input contains two integers nn and mm (2n2,0002 \le n \le 2\\,000, 1m3,0001 \le m \le 3\\,000) denoting number of vertices and number of edges in our graph, respectively.

Each of the following mm lines contains three integers u_i,v_i,w_iu\_i, v\_i, w\_i (1u_i,v_in1 \le u\_i, v\_i \le n, u_iv_iu\_i \neq v\_i, 1w_i100,0001 \le w\_i \le 100\\,000) denoting that ii-th edge goes from vertex u_iu\_i to vertex v_iv\_i and has weight w_iw\_i.

No ordered pair (u_i,v_i)(u\_i, v\_i) will be given more than once.

출력

Output should contain one number --- number of ordered pairs of vertices which have its distance computed incorrectly by Radewoosh's algorithm.