#include <iostream>
#include <vector>
#define INF 1e9 //๋ฌดํ์ ์๋ฏธํ๋ ๊ฐ์ผ๋ก 10์ต์ ์ง์
using namespace std;
int graph[101][101];
int n, m,cnt; //n=๋์์ ๊ฐ์, m=๋ฒ์ค์ ๊ฐ์
int path[101][101];
void findCost(int a, int b) { //๊ฒฝ๋ก์ ํฌํจ๋ ๋์์ ๊ฐ์๋ฅผ ๊ตฌํ๋ ํจ์
if (path[a][b] != INF) {
cnt++;
findCost(a, path[a][b]);
findCost(path[a][b], b);
}
}
void findPath(int a, int b) { //์ฌ๊ท์ ์ผ๋ก ํธ์ถํ๋ฉด์ ๊ฒฝ๋ก๋ฅผ ์ถ๋ ฅํ๋ ํจ์
if (path[a][b] != INF) {
findPath(a, path[a][b]);
cout << path[a][b] << ' ';
findPath(path[a][b], b);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < 101; i++) { //์ต๋จ ๊ฑฐ๋ฆฌ ํ
์ด๋ธ์ ๋ฌดํ์ผ๋ก ์ด๊ธฐํ;
fill(graph[i], graph[i] + 101, INF);
fill(path[i], path[i] + 101, INF);
}
for (int a = 1; a <= n; a++) { //์๊ธฐ ์์ ์์ ์๊ธฐ ์์ ์ผ๋ก ๊ฐ๋ ๋น์ฉ์ 0
for (int b = 1; b <= n; b++) {
if (a == b) {
graph[a][b] = 0;
path[a][b] = 0;
}
}
}
for (int i = 0; i < m; i++) { //๊ฐ์ ์ ๋ณด ์
๋ ฅ
int a, b, c; cin >> a >> b >> c;
graph[a][b] = min(graph[a][b], c); //a์์ b๊น์ง ๊ฐ๋๋ฐ c๋งํผ์ ๋น์ฉ์ด ๋ ๋ค.
}
for (int k = 1; k <= n; k++) { //ํ๋ก์ด๋-์์ฌ ์๊ณ ๋ฆฌ์ฆ ์ํ
for (int a = 1; a <= n; a++) {
for (int b = 1; b <= n; b++) {
if (graph[a][k] + graph[k][b] < graph[a][b]) {
graph[a][b] = graph[a][k] + graph[k][b];
path[a][b] = k;
}
// graph[a][b] = min(graph[a][b], graph[a][k] + graph[k][b]);
}
}
}
for (int a = 1; a <= n; a++) { //i->j๋ก ๊ฐ๋๋ฐ ํ์ํ ์ต์ ๋น์ฉ ์ถ๋ ฅ
for (int b = 1; b <= n; b++) {
if (graph[a][b] == INF) cout << 0 << ' ';
else cout << graph[a][b] << ' ';
}
cout << "\n";
}
for (int a = 1; a <= n; a++) {
for (int b = 1; b <= n; b++) {
if (graph[a][b] == INF||a==b) cout << 0<<'\n';
else {
cnt = 2; //์์๊ณผ ๋์ ๋ฌด์กฐ๊ฑด ์ง๋๋ฏ๋ก 2๋ถํฐ ์์
findCost(a, b);
cout << cnt << ' ' << a << ' ';
findPath(a, b);
cout << b << "\n";
}
}
}
}
๋๊ธ