把 output 递归也不好使
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
#define x first
#define y second
using namespace std;
const int N = 3010, M = 20010;
int h[N], e[M], ne[M], idx;
void add(int a, int b)
{
e[ ++ idx] = b, ne[idx] = h[a], h[a] = idx;
}
struct Node
{
int a, b, c;
bool operator < (const Node &W)const
{
if (W.a != a) return W.a < a;
if (W.b != b) return W.b < b;
return W.c < c;
}
};
map<Node, bool> Map;
int f[N][N];
int n, m, k;
queue<pair<int, int>> q;
int path[N];
void output(int u)
{
int stk[N], top = 0;
while (path[u]) stk[ ++ top] = u, u = path[u];
while (top) printf("%d ", stk[top -- ]);
}
int main()
{
scanf("%d%d%d", &n, &m, &k);
while (m -- )
{
int a, b;
scanf("%d%d", &a, &b);
add(a, b), add(b, a);
}
for (int i = 1, a, b, c; i <= k; i ++ )
scanf("%d%d%d", &a, &b, &c),
Map[{a, b, c}] = true;
q.push({0, 1});
while (q.size())
{
auto t = q.front();
q.pop();
int a = t.x, b = t.y;
for (int i = h[b]; i; i = ne[i])
{
int c = e[i];
if (Map[{a, b, c}]) continue;
if (f[b][c]) continue;
path[c] = b;
f[b][c] = f[a][b] + 1;
q.push({b, c});
if (c == n)
output(n);
}
}
return 0;
}