使用到的数据结构:
struct eage {ll u,v,w;};//存储起点,重点,边权de数据类型
eage e[N];//开数组
ll m;//一共m条边
bool vis[N];//防止死循环,在dfs之前判断一下有没有走过
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> PII;
#define pb emplace_back
//#define int ll
#define all(a) a.begin(),a.end()
#define x first
#define y second
#define ps push_back
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
void solve();
const int N = 1e6 + 10;
signed main() {
IOS;
solve();
return 0;
}
struct eage {ll u,v,w;};
eage e[N];
ll idx,m;
bool vis[N];
void dfs(ll u)
{
vis[u] = 1;
for(int i = 1; i <= m; ++ i)
{
if(e[i].u == u)
{
ll v = e[i].v, w = e[i].w;
cout << u << ' ' << v << ' ' << w << endl;
if(vis[v]) continue;
dfs(v);
}
}
}
void solve() {
ll n;
cin >> n >> m;
for(int i = 1; i <= m; ++ i)
{
ll u,v,w;
cin >> u >> v >> w ;
e[i] = {u,v,w};
}
dfs(1);
}