#include <iostream>
using namespace std;
struct node{
int to;
int next;
int w;
}edge[50*50];
int head[50];
int main(){
int n,m;
cout <<"Input node size:";
cin >> n;
cout << "Input edge size:";
cin >> m;
int edge_count = 0;
for (int i = 0; i < n; i++)
{
head[i] = -1;
}
for (int i = 0; i < m; i++)
{
int starts,to_,w;
cout << "start node ,to node, w :";
cin >> starts >> to_ >> w;
edge[edge_count].to = to_;
edge[edge_count].w = w;
edge[edge_count].next = head[starts];
head[starts] = edge_count;
edge_count++;
}
for (int i = 0; i < n; i++)
{
cout << "node:"<<i << endl;
int j = head[i];
while (j!=-1)
{
cout << edge[j].to << " w:" << edge[j].w << endl;
j = edge[j].next;
}
cout <<"----the end ----" << endl;
}
}
07-02
986
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-18
378
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-24