package main import ( "bufio" "container/heap" "fmt" "os" "strconv" ) const inf int = 9999999 func main() { sc.Split(bufio.ScanWords) // indexと島を合わせるために孤立した島0を加えておく n := nextInt() + 1 m := nextInt() q := nextInt() g := newGraph(n) bridge := make([]nodes, m) for i := 0; i < m; i++ { bridge[i].a = nextInt() bridge[i].b = nextInt() } crashed := make(map[int]int) crash := make([]nodes, q) for i := 0; i < q; i++ { crash[i].a = nextInt() crash[i].b = nextInt() crashed[crash[i].a*1000000+crash[i].b] = i + 1 } // 壊れない橋を追加する for i := 0; i < m; i++ { a := bridge[i].a b := bridge[i].b cost := crashed[a*1000000+b] if cost == 0 { cost = inf } g[a] = append(g[a], Edge{to: b, cost: cost}) g[b] = append(g[b], Edge{to: a, cost: cost}) } d := g.dijkstar(n, 1) for i := 2; i < n; i++ { switch d[i] { case inf: fmt.Println("-1") case -1: fmt.Println("0") default: fmt.Println(d[i]) } } } type nodes struct { a, b int } type Edge struct { to int cost int } type Graph [][]Edge func newGraph(n int) Graph { g := make(Graph, n) for i := range g { g[i] = make([]Edge, 0) } return g } func (g *Graph) Find(n int) []Edge { return (*g)[n] } func (g *Graph) dijkstar(n, s int) []int { dist := make([]int, n) // 頂点sからの最短距離 for i := range dist { dist[i] = -1 } que := make(PriorityQueue, 0) heap.Init(&que) dist[s] = inf item := &Item{ node: s, cost: inf, } heap.Push(&que, item) for que.Len() > 0 { p := que.Pop().(*Item) v := p.node if dist[v] > p.cost { continue } for i := 0; i < len((*g)[v]); i++ { e := (*g)[v][i] if dist[e.to] < min(dist[v], e.cost) { dist[e.to] = min(dist[v], e.cost) item := &Item{ cost: dist[e.to], node: e.to, } heap.Push(&que, item) } } } return dist } type Item struct { node int // 頂点の番号 cost int // 最短距離 index int } // A PriorityQueue implements heap.Interface and holds Items. type PriorityQueue []*Item func (pq PriorityQueue) Len() int { return len(pq) } func (pq PriorityQueue) Less(i, j int) bool { return pq[i].cost > pq[j].cost } func (pq PriorityQueue) Swap(i, j int) { pq[i], pq[j] = pq[j], pq[i] pq[i].index = i pq[j].index = j } func (pq *PriorityQueue) Push(x interface{}) { n := len(*pq) item := x.(*Item) item.index = n *pq = append(*pq, item) } func (pq *PriorityQueue) Pop() interface{} { old := *pq n := len(old) item := old[n-1] item.index = -1 // for safety *pq = old[0 : n-1] return item } // update modifies the priority and value of an Item in the queue. func (pq *PriorityQueue) update(item *Item, node, dist int) { item.node = node item.cost = dist heap.Fix(pq, item.index) } var sc = bufio.NewScanner(os.Stdin) func nextLine() string { sc.Scan() return sc.Text() } func nextInt() int { i, _ := strconv.Atoi(nextLine()) return i } func max(a, b int) int { if a > b { return a } return b } func min(a, b int) int { if a < b { return a } return b }