#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct edge
{
int to,cost;
};
vector<edge> G[10000];
int main()
{
int v,e;
while(cin>>v>>e)
{
int i,j;
for(i=0;i<e;i++)
{
int st;
edge es;
cin>>st>>es.to>>es.cost;
G[st].push_back(es);
}
for(i=0;i<v;i++)
{
for(j=0;j<G[i].size();j++)
{
cout<<G[i][j].to<<" ";
}
cout<<endl;
}
for(i=0;i<v;i++)
{
for(j=0;j<G[i].size();j++)
{
cout<<G[i][j].cost<<" ";
}
cout<<endl;
}
}
return 0;
}
图论 邻接表实现 动态数组实现
最新推荐文章于 2021-10-21 01:56:11 发布