#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 1005;
struct Edge {
int w;
int to;
int next; //next[i]表示与第i条边同起点的上一条边的储存位置
}edge[MAXN];
int id;
int head[MAXN];
void add(int u, int v, int w) {
edge[id].w = w;
edge[id].to = v; //edge[i]表示第i条边的终点
edge[id].next = head[u]; //head[i]表示以i为起点的最后一条边的储存位置
head[u] = id++;
}
int main()
{
memset(head, -1, sizeof(head));
int n;
cin >> n;
int x, y, w;
while (n--)
{
cin >> x >> y >> w;
add(x, y, w);
}
int start;
cin >> start;
for (int i = head[start]; i != -1; i = edge[i].next)
{
cout << start << "->" << edge[i].to << " " << edge[i].next << endl;
}
return 0;
}
链式前向星
最新推荐文章于 2023-07-29 17:46:16 发布