#include<bits/stdc++.h>usingnamespacestd;structNode{intdata, next; };inthead, n, a, b, c;vector<Node>node(100005);vector<bool>vis(10005); queue<int> q1, q2;intmain(){scanf("%d%d", &head, &n);while(n--) {scanf("%d%d%d", &a, &b, &c); node[a].data = b; node[a]...