#include using namespace std; const int inf = 1e9; 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] = inf; g[b][a] = inf; } 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; } priority_queue> q; q.emplace(inf, 0); vector dist(n); dist[0] = inf; while (!q.empty()) { int d, curr; tie(d, curr) = q.top(); q.pop(); if (d < 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.emplace(dist[next], next); } } } for (int i = 1; i < n; i++) { if (dist[i] == inf) dist[i] = -1; printf("%d\n", dist[i]); } }