507_E. Breaking Good
Breaking Good is a new video game which a lot of gamers want to have. There is a certain level in the game that is really difficult even for experienced gamers.

Walter William, the main character of the game, wants to join a gang called Los Hermanos (The Brothers). The gang controls the whole country which consists of n cities with m bidirectional roads connecting them. There is no road is connecting a city to itself and for any two cities there is at most one road between them. The country is connected, in the other words, it is possible to reach any city from any other city using the given roads. 

The roads aren't all working. There are some roads which need some more work to be performed to be completely functioning.

The gang is going to rob a bank! The bank is located in city 1. As usual, the hardest part is to escape to their headquarters where the police can't get them. The gang's headquarters is in city n. To gain the gang's trust, Walter is in charge of this operation, so he came up with a smart plan.

First of all the path which they are going to use on their way back from city 1 to their headquarters n must be as short as possible, since it is important to finish operation as fast as possible.

Then, gang has to blow up all other roads in country that don't lay on this path, in order to prevent any police reinforcements. In case of non-working road, they don't have to blow up it as it is already malfunctional. 

If the chosen path has some roads that doesn't work they'll have to repair those roads before the operation.

Walter discovered that there was a lot of paths that satisfied the condition of being shortest possible so he decided to choose among them a path that minimizes the total number of affected roads (both roads that have to be blown up and roads to be repaired).

Can you help Walter complete his task and gain the gang's trust?

Input

The first line of input contains two integers n, m (2 ≤ n ≤ 105, <image>), the number of cities and number of roads respectively.

In following m lines there are descriptions of roads. Each description consists of three integers x, y, z (1 ≤ x, y ≤ n, <image>) meaning that there is a road connecting cities number x and y. If z = 1, this road is working, otherwise it is not.

Output

In the first line output one integer k, the minimum possible number of roads affected by gang.

In the following k lines output three integers describing roads that should be affected. Each line should contain three integers x, y, z (1 ≤ x, y ≤ n, <image>), cities connected by a road and the new state of a road. z = 1 indicates that the road between cities x and y should be repaired and z = 0 means that road should be blown up. 

You may output roads in any order. Each affected road should appear exactly once. You may output cities connected by a single road in any order. If you output a road, it's original state should be different from z.

After performing all operations accroding to your plan, there should remain working only roads lying on some certain shortest past between city 1 and n.

If there are multiple optimal answers output any.

Examples

Input

2 1
1 2 0


Output

1
1 2 1


Input

4 4
1 2 1
1 3 0
2 3 1
3 4 1


Output

3
1 2 0
1 3 1
2 3 0


Input

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


Output

3
2 3 0
1 5 0
6 8 1

Note

In the first test the only path is 1 - 2

In the second test the only shortest path is 1 - 3 - 4

In the third test there are multiple shortest paths but the optimal is 1 - 4 - 6 - 8
```python
from collections import deque

def bfs(n, v, s, t):
    dis = [n] * n
    load = [n] * n
    path = [None] * n
    q = deque([s])
    dis[s] = 0
    load[s] = 0
    while (q):
        node = q.popleft()
        for i in range(len(v[node])):
            nb = v[node][i][0]
            status = v[node][i][1]
            tmp_dis = dis[node] + 1
            tmp_load = load[node] + (status != 1)
            if ((tmp_dis, tmp_load) < (dis[nb], load[nb])):
                dis[nb] = tmp_dis
                load[nb] = tmp_load
                path[nb] = node
                if (node != t): q.append(nb)
        if (node == t):
            break
    node = t
    opt = set()
    while (node != s):
        opt.add((min(node, path[node]), max(node, path[node])))
        node = path[node]
    return dis[t], load[t], opt

#def sp(s, t):
    ## dijkstra
    #global m, n, v, st, l_min, w_min, opt
    #current = s
    #visited = set([s])
    #dis = {}
    #dis[s] = 0
    #path = [[] for _ in xrange(n)]
    #path[s] = [[]]
    #load = [[] for _ in xrange(n)]
    #load[s] = [0]
    #while (current != t):
        #if (debug >= 2):
            #print 'current=%d' % current
        #for i in xrange(len(v[current])):
            #nb = v[current][i]
            #status = st[current][i]
            #if (debug >= 2):
                #print ' nb=%d, st=%d:' % (nb, status),
            #if (not dis.has_key(nb) or dis[nb] > 1 + dis[current]):
                ## update
                #dis[nb] = 1 + dis[current]
                #load[nb] = []
                #path[nb] = []
                #for j in xrange(len(load[current])):
                    #path[nb].append(path[current][j][:])
                    #path[nb][j].append((current, nb))
                    #if (status == 0):
                        #load[nb].append(load[current][j] + 1)
                    #else:
                        #load[nb].append(load[current][j])
                #if (debug >= 2):
                    #print 'Updated'
            #elif (dis[nb] == 1 + dis[current]):
                ## append
                #for j in xrange(len(load[current])):
                    #path[nb].append(path[current][j][:])
                    #path[nb][len(path[nb]) - 1].append((current, nb))
                    #if (status == 0): load[nb].append(1 + load[current][j])
                    #else: load[nb].append(load[current][j])
                #if (debug >= 2):
                    #print 'Appended'
            #else:
                #if (debug >= 2):
                    #print 'Passed'
        #sorted_idx = sorted(dis, key = dis.get)
        #if (debug >= 2): print sorted_idx
        #idx = 0
        #while (sorted_idx[idx] in visited): idx += 1
        #current = sorted_idx[idx]
        #visited.add(current)
    #w_min = min(load[t])
    #l_min = dis[t]
    #opt = tuple(path[t][load[t].index(w_min)])
    #return 0

#def dfs(s, t, visited, path, l, w):
    #global m, n, v, st, l_min, w_min, opt
    ##print path
    #if (s == t):
        #if (l < l_min):
            #l_min = l
            #w_min = w
            #opt = tuple(path)
        #else:
            #if (w < w_min):
                #w_min = w
                #opt = tuple(path)
        #return 0
    #if (l >= l_min): return 0
    ##if (w >= w_min): return 0
    #for i in xrange(len(v[s])):
        #if (v[s][i] in visited): continue
        #visited.add(v[s][i])
        #path.append((s, v[s][i]))
        #if (st[s][i] == 1):
            #dfs(v[s][i], t, visited, path, l + 1, w)
        #else:
            #dfs(v[s][i], t, visited, path, l + 1, w + 1)
        #visited.remove(v[s][i])
        #path.pop(len(path) - 1)
    #return 0

global debug
debug = 0

#global m, n, v, st, l_min, w_min
n, m = list(map(int, input().split()))
#e = []
v = [[] for _ in range(n)]
a = 0 # bad count
b = 0 # good count
#l_min = n
#w_min = n
#opt = ()
for i in range(m):
    v1, v2, status = list(map(int, input().split()))
    if (status == 0): a += 1
    else: b += 1
    v[v1 - 1].append((v2 - 1, status))
    v[v2 - 1].append((v1 - 1, status))
    #e.append((v1, v2, status))
if (debug >= 1): t0 = time.time()
#dfs(0, n - 1, set(), [], 0, 0)
#sp(n - 1, 0)
#sp(0, n - 1)
l_min, w_min, opt = bfs(n, v, 0, n - 1)
#l_min, w_min, opt = bfs(n, v, st, n - 1, 0)
print(b - l_min + 2 * w_min)
#print opt
#for i in xrange(len(e)):
#    if ((e[i][0] - 1, e[i][1] - 1) in opt or (e[i][1] - 1, e[i][0] - 1) in opt):
#        if (e[i][2] == 0): print '%d %d 1' % (e[i][0], e[i][1])
#    else:
#        if (e[i][2] == 1): print '%d %d 0' % (e[i][0], e[i][1])
#for i in xrange(len(e)):
#    if ((min(e[i][0] - 1, e[i][1] - 1), max(e[i][0] - 1, e[i][1] - 1)) in opt):
#        if (e[i][2] == 0): print '%d %d 1' % (e[i][0], e[i][1])
#    else:
#        if (e[i][2] == 1): print '%d %d 0' % (e[i][0], e[i][1])
for v1 in range(n):
    for v2, status in v[v1]:
        if (v2 < v1): continue
        if ((v1, v2) in opt):
            if (status == 0): print('%d %d 1' % (v1 + 1, v2 + 1))
        else:
            if (status == 1): print('%d %d 0' % (v1 + 1, v2 + 1))
if (debug >= 1): print('%f' % (time.time() - t0))

```