/*请从main开始看*/
/*
SampleInput:
6 8 3
0 5
2 4
2 3
1 2
0 1
3 4
3 5
0 2
1 5
2 4
2 5
4 2 1
0 1
2 3
2 1
*/
#include<cstdio>
#include<cstring>
#include<list>
#include<queue>
#include<stack>
using namespace std;
const int maxn = 1000002;
list<int> point[maxn];///当然,你也可以使用vector实现
queue<int> que;
bool vis[maxn];
int edgeTo[maxn], end;
stack<int> path;
///采用队列实现
inline void bfs(int s)
{
memset(vis, 0, sizeof(vis));
while (!que.empty())
que.pop();
vis[s] = true;
que.push(s);
while (!que.empty())
{
int v = que.front();
que.pop();
list<int>::iterator it;
for (it = point[v].begin(); it != point[v].end(); ++it)
{
int w = (int) * it;
if (!vis[w])
{
edgeTo[w] = v;
vis[w] = true;
if (w == end)
return;
que.push(w);
}
}
}
}
inline void printpath(int v, int w)
{
memset(edgeTo, -1, sizeof(edgeTo));
while (!path.empty())
path.pop();
end = w;
bfs(v);
for (int x = w; x != v; x = edgeTo[x])///先从w到v
{
if (~edgeTo[x]) /// edgeTo[x] != -1
path.push(x);
else ///说明v,w在两个不同的连通分量上
{
printf("-1\n");
return;
}
}
printf("%d", v);
while (!path.empty())
{
printf(" %d", path.top());
path.pop();
}
printf("\n");
end = -1;
}
int main(void)
{
int n, m, k, temp, v, w;///点数=n,边数=m,查询数=k
while (~scanf("%d%d%d", &n, &m, &k))
{
///0. 初始化
temp = m;
while (temp--)
{
scanf("%d%d", &v, &w);///这里输入要求为0~(n-1)
point[v].push_front(w);
point[w].push_front(v);
}
///1. 判断是否存在v到w的路径/求v到w的一条最短路径(保证v,w在范围内)
while (k--)
{
scanf("%d%d", &v, &w);///v!=w
printpath(v, w);
}
///0. 初始化
for (int i = 0; i < n; ++i)
point[i].clear();
printf("\n");
}
return 0;
}