#include using namespace std; int main() { int N, M, Q; map< int, int > g[100000]; scanf("%d %d %d", &N, &M, &Q); for(int i = 0; i < M + Q; i++) { int A, B; scanf("%d %d", &A, &B); --A, --B; g[A][B] = g[B][A] = i < M ? Q : i - M; } vector< queue< int > > que(Q + 1); vector< int > v(N, -1); v[0] = Q; que[Q].push(0); for(int i = Q; i > 0; i--) { while(!que[i].empty()) { int curr = que[i].front(); que[i].pop(); if(i < v[curr]) continue; for(auto& e : g[curr]) { int cost = min(v[curr], e.second); if(v[e.first] < cost) { v[e.first] = cost; que[cost].push(e.first); } } } } for(int i = 1; i < N; i++) { printf("%d\n", v[i] == Q ? -1 : v[i] + 1); } }