#include #ifdef DEBUG #include #else #define dump(...) #endif /** * @title グラフ用テンプレート * @docs graph_template.md */ template class Edge{ public: int from,to; Cost cost; Edge() {} Edge(int to, Cost cost): to(to), cost(cost){} Edge(int from, int to, Cost cost): from(from), to(to), cost(cost){} }; template using Graph = std::vector>>; template using Tree = std::vector>>; template void add_edge(C &g, int from, int to, T w = 1){ g[from].emplace_back(from, to, w); } template void add_undirected(C &g, int a, int b, T w = 1){ add_edge(g, a, b, w); add_edge(g, b, a, w); } /** * @docs input_tuple_vector.md */ template void input_tuple_vector_init(T &val, int N, std::index_sequence){ (void)std::initializer_list{ (void(std::get(val).resize(N)), 0)... }; } template void input_tuple_vector_helper(T &val, int i, std::index_sequence){ (void)std::initializer_list{ (void(std::cin >> std::get(val)[i]), 0)... }; } template auto input_tuple_vector(int N){ std::tuple...> ret; input_tuple_vector_init(ret, N, std::make_index_sequence()); for(int i = 0; i < N; ++i){ input_tuple_vector_helper(ret, i, std::make_index_sequence()); } return ret; } template struct YenAlgorithm{ Graph g; int s, t, K, N; std::vector> valid; using Path = std::pair>; std::vector> result; std::priority_queue, std::greater> stock; YenAlgorithm(Graph g, int s, int t, int K): g(g), s(s), t(t), K(K), N(g.size()){run();} void run(){ valid.resize(N); for(int i = 0; i < N; ++i){ valid[i].assign(g[i].size(), true); } result.resize(K); for(int i = 0; i < K; ++i){ if(i == 0){ auto res = shortest_path(s); if(res){ stock.push(*res); } }else{ std::vector prev_path; { int cur = s; for(auto u : result[i-1].value().second){ prev_path.push_back(cur); cur = g[cur][u].to; } prev_path.push_back(t); dump(prev_path); } std::vector check(i, true); for(int k = 0; k < (int)prev_path.size() - 1; ++k){ const int u = prev_path[k]; for(int j = 0; j < i; ++j){ if(check[j]){ valid[prev_path[k]][(*result[j]).second[k]] = false; } } dump(check, valid[prev_path[k]]); auto res = shortest_path(u); //dump(res); if(res){ auto [c, p] = *res; std::vector temp; for(int j = 0; j < k; ++j){ int v = (*result[i-1]).second[j]; c += g[prev_path[j]][v].cost; temp.push_back(v); } temp.insert(temp.end(), p.begin(), p.end()); //std::swap(temp, p); dump(std::make_pair(c, temp)); stock.emplace(c, temp); } for(int j = 0; j < i; ++j){ if(check[j]){ valid[prev_path[k]][(*result[j]).second[k]] = true; } } for(int j = 0; j < i; ++j){ if(check[j]){ if(prev_path[k+1] != g[prev_path[k]][(*result[j]).second[k]].to){ check[j] = false; } } } } } std::cerr << "\n"; if(stock.empty()) break; result[i] = stock.top(); stock.pop(); while(not stock.empty() and stock.top() == result[i]){ stock.pop(); } } } std::optional>> shortest_path(int from){ std::vector visited(N, false); std::vector> dist(N); std::vector> restore(N); std::priority_queue< std::pair, std::vector>, std::greater>> pq; dist[from] = 0; pq.emplace(0, from); while(not pq.empty()){ auto [d, i] = pq.top(); pq.pop(); if(visited[i]) continue; visited[i] = true; for(int k = 0; k < (int)g[i].size(); ++k){ if(not valid[i][k]) continue; auto &e = g[i][k]; if(not dist[e.to]){ dist[e.to] = d + e.cost; pq.emplace(*dist[e.to], e.to); restore[e.to] = std::make_pair(i, k); }else{ if(*dist[e.to] > d + e.cost){ dist[e.to] = d + e.cost; if(not visited[e.to]) pq.emplace(*dist[e.to], e.to); restore[e.to] = std::make_pair(i, k); } } } } if(dist[t]){ std::vector p; int cur = t; while(cur != from){ auto [i, j] = restore[cur]; p.push_back(j); cur = i; } std::reverse(p.begin(), p.end()); return {std::make_pair(*dist[t], p)}; }else{ return {}; } } }; int main(){ int N, M, K; std::cin >> N >> M >> K; int X, Y; std::cin >> X >> Y; --X, --Y; auto [p, q] = input_tuple_vector(N); Graph g(N); for(int i = 0; i < M; ++i){ int P, Q; std::cin >> P >> Q; --P, --Q; long double dx = p[P] - p[Q]; long double dy = q[P] - q[Q]; long double L = std::sqrt(dx * dx + dy * dy); add_undirected(g, P, Q, L); } auto res = YenAlgorithm(g, X, Y, K).result; /* std::cerr << "\n"; for(auto a : res){ std::vector p; int cur = X; for(auto u : a->second){ p.push_back(cur); cur = g[cur][u].to; } p.push_back(Y); dump(p); } dump(res);*/ for(auto x : res){ if(not x){ std::cout << -1 << "\n"; }else{ std::cout << std::fixed << std::setprecision(12) << x->first << "\n"; } } return 0; }