利用到的数据结构
struct eage{ll v,w;};//存储重点和,边权 vector e[N];//数组下标作为起点 ll n,m; bool vis[N];//判断是否走过
#include using namespace std; typedef long long ll; typedef double db; typedef long double ldb; typedef pair pii; typedef pair 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 v,w;}; vector e[N]; ll n,m; bool vis[N]; void dfs(ll u) { vis[u] = 1; for(auto it : e[u]) { ll v = it.v , w = it.w; cout << u << " " << v << ' ' << w << endl; if(vis[v]) continue; dfs(v); } } void solve() { cin >> n >> m; for(int i = 1; i <= m; ++ i) { ll u,v,w; cin >> u >> v >> w; e[u].ps({v,w}); } dfs(1); } //输入 //7 6 //4 3 90 //1 4 30 //5 7 80 //5 6 60 //1 5 20 //5 2 70 //输出 //1 4 30 //4 3 90 //1 5 20 //5 7 80 //5 6 60 //5 2 70
上一篇:公众平台开源软件_开源软件声明