#include using namespace std; template bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } int main() { int n, m, Q; cin >> n >> m >> Q; vector> g(n); for (int i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); a--; b--; g[a][b] = Q + 1; g[b][a] = Q + 1; } for (int i = 0; i < Q; i++) { int c, d; scanf("%d %d", &c, &d); c--; d--; g[c][d] = i + 1; g[d][c] = i + 1; } vector> q(Q + 2); q[Q + 1].push(0); vector dist(n); dist[0] = Q + 1; for (int i = Q + 1; i >= 1; i--) { while (!q[i].empty()) { int curr = q[i].front(); q[i].pop(); if (i < dist[curr]) continue; for (auto kv : g[curr]) { int next = kv.first; int cost = kv.second; if (chmax(dist[next], min(dist[curr], cost))) { q[dist[next]].push(next); } } } } for (int i = 1; i < n; i++) { if (dist[i] == Q + 1) dist[i] = -1; printf("%d\n", dist[i]); } }