#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define ALL(x) (x).begin(), (x).end() #define BIT(n) (1LL<<(n)) #define SZ(x) ((int)(x).size()) #define fst first #define snd second typedef long long ll; typedef vector vi;typedef vector vvi;typedef pair pii;typedef vector vpii; const int inf = 1e9; void Main() { int N, M, Q; scanf("%d%d%d", &N, &M, &Q); vector E(N); vector> ma(N); rep(i, M) { int u, v; scanf("%d%d", &u, &v); u--; v--; ma[u][v] = SZ(E[u]); ma[v][u] = SZ(E[v]); E[u].emplace_back(v, inf); E[v].emplace_back(u, inf); } rep(i, Q) { int c, d; scanf("%d%d", &c, &d); c--; d--; assert(E[c][ma[c][d]].fst == d); assert(E[d][ma[d][c]].fst == c); E[c][ma[c][d]].snd = i; E[d][ma[d][c]].snd = i; } // 大きい方が偉い vi D(N, -1); priority_queue q; D[0] = inf; q.emplace(inf, 0); while (!q.empty()) { int c, v; tie(c, v) = q.top(); q.pop(); if (D[v] > c) continue; for (auto&& nex : E[v]) { int nv = nex.first; int nc = min(c, nex.second); if (D[nv] < nc) { D[nv] = nc; q.emplace(nc, nv); } } } rep(i, 1, N) { if (D[i] == inf) { puts("-1"); } else { _p("%d\n", D[i]+1); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }