結果
問題 | No.1069 電柱 / Pole (Hard) |
ユーザー |
![]() |
提出日時 | 2020-05-29 22:35:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,471 bytes |
コンパイル時間 | 2,997 ms |
コンパイル使用メモリ | 216,680 KB |
最終ジャッジ日時 | 2025-01-10 17:51:11 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 77 WA * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define modulo 1000000007 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 10000000000000000.0 double eps = 1e-7; int main(){ int N,M,K,X,Y; cin>>N>>M>>K>>X>>Y; X--;Y--; vector<double> x(N),y(N); for(int i=0;i<N;i++)cin>>x[i]>>y[i]; vector<vector<pair<int,double>>> E(N,vector<pair<int,double>>()); for(int i=0;i<M;i++){ int u,v; cin>>u>>v; u--;v--; double d = sqrt(pow(x[u]-x[v],2.0)+pow(y[u]-y[v],2.0)); E[u].emplace_back(v,d); E[v].emplace_back(u,d); } vector<double> ans; vector<int> cnt(N,0); priority_queue<pair<pair<double,int>,vector<bool>>,vector<pair<pair<double,int>,vector<bool>>>,greater<pair<pair<double,int>,vector<bool>>>> Q; { vector<bool> t(N,false); t[X] = true; Q.emplace(make_pair(0.0,X),t); } while(Q.size()!=0){ double D1 = Q.top().first.first; int from = Q.top().first.second; vector<bool> b = Q.top().second; Q.pop(); if(cnt[from]>=K)continue; cnt[from]++; if(from==Y)ans.push_back(D1); for(int i=0;i<E[from].size();i++){ int to = E[from][i].first; if(cnt[to]>=K)continue; if(b[to])continue; double D2 = E[from][i].second; vector<bool> t = b; t[to] = true; Q.emplace(make_pair(D1+D2,to),t); } //cout<<Q.top().first.first<<endl; } sort(ans.begin(),ans.end()); for(int i=0;i<K;i++){ if(i>=ans.size())cout<<-1<<endl; else cout<<fixed<<setprecision(10)<<ans[i]<<endl; } return 0; }