标签:图的遍历 cpp pre fir void ace max name namespace
#include <cstdio>
#include <iostream>
#define maxlen 100005
using namespace std;
int n, m;
int u[maxlen], v[maxlen];
int first[maxlen], next1[maxlen];
void dfs()
{
for (int i = 1; i <=n; i++)
{
int k = first[i];
while (k != -1)
{
cout << u[k] << v[k];
k = next1[k];
}
}
}
int main()
{
int mm;
cin>>n>>m;
mm=m;
for (int i = 1; i <= n; i++)
first[i] = -1;
for (int i = 1; i <= m; i++)
{
cin >> u[i] >> v[i];
next1[i] = first[u[i]];
first[u[i]] = i;
}
dfs();
return 0;
}
/*
5 4
1 2
2 4
4 3
4 5
*/
标签:图的遍历 cpp pre fir void ace max name namespace
原文地址:https://www.cnblogs.com/coodyz/p/10834716.html