結果

問題 No.1069 電柱 / Pole (Hard)
ユーザー beetbeet
提出日時 2020-05-29 22:16:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,569 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 217,660 KB
実行使用メモリ 104,940 KB
最終ジャッジ日時 2024-04-24 05:08:22
合計ジャッジ時間 6,003 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
35,632 KB
testcase_01 AC 9 ms
35,648 KB
testcase_02 AC 9 ms
35,576 KB
testcase_03 AC 11 ms
35,720 KB
testcase_04 AC 188 ms
104,940 KB
testcase_05 WA -
testcase_06 AC 18 ms
37,420 KB
testcase_07 AC 22 ms
37,544 KB
testcase_08 AC 20 ms
38,416 KB
testcase_09 AC 21 ms
38,368 KB
testcase_10 AC 14 ms
36,728 KB
testcase_11 AC 11 ms
35,876 KB
testcase_12 AC 13 ms
36,164 KB
testcase_13 AC 29 ms
39,880 KB
testcase_14 AC 34 ms
38,752 KB
testcase_15 AC 28 ms
39,792 KB
testcase_16 AC 16 ms
37,112 KB
testcase_17 AC 18 ms
37,720 KB
testcase_18 AC 17 ms
37,316 KB
testcase_19 AC 31 ms
39,696 KB
testcase_20 AC 40 ms
40,740 KB
testcase_21 AC 21 ms
38,424 KB
testcase_22 AC 39 ms
39,028 KB
testcase_23 AC 36 ms
41,172 KB
testcase_24 AC 17 ms
38,052 KB
testcase_25 AC 18 ms
38,228 KB
testcase_26 AC 20 ms
38,112 KB
testcase_27 AC 19 ms
38,112 KB
testcase_28 AC 20 ms
38,240 KB
testcase_29 AC 13 ms
36,200 KB
testcase_30 AC 10 ms
35,664 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 11 ms
35,864 KB
testcase_34 AC 11 ms
35,608 KB
testcase_35 AC 10 ms
35,660 KB
testcase_36 AC 11 ms
35,764 KB
testcase_37 AC 17 ms
37,472 KB
testcase_38 AC 15 ms
36,840 KB
testcase_39 AC 11 ms
35,896 KB
testcase_40 AC 13 ms
36,656 KB
testcase_41 AC 19 ms
37,704 KB
testcase_42 AC 16 ms
37,056 KB
testcase_43 AC 11 ms
35,924 KB
testcase_44 AC 21 ms
38,536 KB
testcase_45 AC 24 ms
39,236 KB
testcase_46 AC 23 ms
39,200 KB
testcase_47 AC 18 ms
37,548 KB
testcase_48 AC 23 ms
38,424 KB
testcase_49 AC 15 ms
37,268 KB
testcase_50 AC 14 ms
36,564 KB
testcase_51 AC 19 ms
38,064 KB
testcase_52 AC 14 ms
36,340 KB
testcase_53 AC 17 ms
37,476 KB
testcase_54 AC 11 ms
35,780 KB
testcase_55 AC 11 ms
35,812 KB
testcase_56 AC 12 ms
35,912 KB
testcase_57 AC 12 ms
35,860 KB
testcase_58 AC 11 ms
35,828 KB
testcase_59 AC 11 ms
35,836 KB
testcase_60 AC 11 ms
35,844 KB
testcase_61 AC 11 ms
35,732 KB
testcase_62 AC 11 ms
35,744 KB
testcase_63 AC 11 ms
35,788 KB
testcase_64 AC 11 ms
35,880 KB
testcase_65 AC 12 ms
35,684 KB
testcase_66 AC 11 ms
35,904 KB
testcase_67 AC 11 ms
35,720 KB
testcase_68 AC 11 ms
35,768 KB
testcase_69 AC 13 ms
36,268 KB
testcase_70 AC 12 ms
36,160 KB
testcase_71 AC 12 ms
36,260 KB
testcase_72 AC 11 ms
36,072 KB
testcase_73 AC 11 ms
36,088 KB
testcase_74 AC 13 ms
36,208 KB
testcase_75 AC 15 ms
36,344 KB
testcase_76 AC 20 ms
38,184 KB
testcase_77 AC 19 ms
37,792 KB
testcase_78 AC 11 ms
35,824 KB
testcase_79 AC 28 ms
39,964 KB
testcase_80 AC 21 ms
38,052 KB
testcase_81 AC 18 ms
38,240 KB
testcase_82 AC 34 ms
40,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE

using D = double;
const int MAX = 2020;
D dist[MAX][MAX];

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,m,k;
  cin>>n>>m>>k;
  int x,y;
  cin>>x>>y;
  x--;y--;

  for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
      dist[i][j]=-1;

  vector<D> ps(n),qs(n);
  for(int i=0;i<n;i++) cin>>ps[i]>>qs[i];

  vector<vector<int>> G(n);
  for(int i=0;i<m;i++){
    int u,v;
    cin>>u>>v;
    u--;v--;
    D d=hypot(ps[u]-ps[v],qs[u]-qs[v]);
    dist[u][v]=dist[v][u]=d;
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }

  struct Path{
    vector<int> vs;
    bool isvalid(int nxt){
      assert(!vs.empty());
      //cerr<<"sz:"<<vs.size()<<endl;
      //cerr<<vs.back()<<' '<<nxt<<endl;
      //cerr<<dist[vs.back()][nxt]<<endl;
      if(dist[vs.back()][nxt]<0) return false;
      //cerr<<"sz:"<<vs.size()<<endl;
      if(count(vs.begin(),vs.end(),nxt)) return false;
      //cerr<<"sz:"<<vs.size()<<endl;
      return true;
      //cerr<<"sz:"<<vs.size()<<endl;
    }
    D len;
    bool operator<(const Path &o)const{
      if(len!=o.len) return len<o.len;
      return vs<o.vs;
    };
    bool operator>(const Path &o)const{
      if(len!=o.len) return len>o.len;
      return vs>o.vs;
    };
  };

  priority_queue<Path, vector<Path>, greater<Path>> pq;
  vector<set<Path>> dp(n);

  auto push=[&](Path p){
    // cerr<<p.vs.back()<<endl;
    // cerr<<dp[p.vs.back()].size()<<endl;
    if(dp[p.vs.back()].count(p)) return;
    dp[p.vs.back()].emplace(p);
    pq.emplace(p);
  };

  {
    Path p;
    p.vs.emplace_back(x);
    p.len=0;
    push(p);
  }

  vector<int> cnt(n,0);
  while(!pq.empty()){
    Path p=pq.top();pq.pop();
    int v=p.vs.back();

    // cerr<<v<<' '<<p.len<<endl;

    cnt[v]++;
    if(cnt[y]==k) break;
    if(cnt[v]>k) continue;

    for(int u:G[v]){
      // cerr<<v<<"->"<<u<<endl;
      if(!p.isvalid(u)) continue;
      // cerr<<v<<"->"<<u<<endl;
      p.vs.emplace_back(u);
      p.len+=dist[v][u];
      push(p);
      p.vs.pop_back();
      p.len-=dist[v][u];
    }
  }

  for(int i=0;i<k;i++){
    if(dp[y].empty()){
      cout<<-1<<newl;
      continue;
    }
    cout<<dp[y].begin()->len<<newl;
    dp[y].erase(dp[y].begin());
  }
  return 0;
}
0