結果

問題 No.1069 電柱 / Pole (Hard)
ユーザー beetbeet
提出日時 2022-12-06 00:37:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,077 bytes
コンパイル時間 2,472 ms
コンパイル使用メモリ 218,712 KB
実行使用メモリ 211,840 KB
最終ジャッジ日時 2024-04-20 22:12:01
合計ジャッジ時間 12,060 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
35,584 KB
testcase_01 AC 23 ms
35,712 KB
testcase_02 AC 23 ms
35,584 KB
testcase_03 AC 23 ms
35,712 KB
testcase_04 AC 671 ms
198,684 KB
testcase_05 WA -
testcase_06 AC 98 ms
50,984 KB
testcase_07 AC 144 ms
58,344 KB
testcase_08 AC 56 ms
44,168 KB
testcase_09 AC 152 ms
59,216 KB
testcase_10 AC 28 ms
37,196 KB
testcase_11 AC 26 ms
36,608 KB
testcase_12 AC 25 ms
36,224 KB
testcase_13 AC 228 ms
66,828 KB
testcase_14 AC 49 ms
42,548 KB
testcase_15 AC 55 ms
43,540 KB
testcase_16 AC 39 ms
40,556 KB
testcase_17 AC 40 ms
39,632 KB
testcase_18 AC 32 ms
38,380 KB
testcase_19 AC 291 ms
74,116 KB
testcase_20 AC 421 ms
87,804 KB
testcase_21 AC 162 ms
59,768 KB
testcase_22 AC 46 ms
42,012 KB
testcase_23 AC 406 ms
80,840 KB
testcase_24 AC 67 ms
49,124 KB
testcase_25 AC 145 ms
62,168 KB
testcase_26 AC 98 ms
62,180 KB
testcase_27 AC 103 ms
62,308 KB
testcase_28 AC 99 ms
62,132 KB
testcase_29 AC 27 ms
36,736 KB
testcase_30 AC 23 ms
35,712 KB
testcase_31 AC 21 ms
35,584 KB
testcase_32 AC 22 ms
35,712 KB
testcase_33 AC 22 ms
35,584 KB
testcase_34 AC 22 ms
35,584 KB
testcase_35 AC 22 ms
35,712 KB
testcase_36 AC 22 ms
35,584 KB
testcase_37 AC 104 ms
51,128 KB
testcase_38 AC 47 ms
41,260 KB
testcase_39 AC 23 ms
35,712 KB
testcase_40 AC 26 ms
36,736 KB
testcase_41 AC 43 ms
41,048 KB
testcase_42 AC 64 ms
44,328 KB
testcase_43 AC 47 ms
42,108 KB
testcase_44 AC 174 ms
64,068 KB
testcase_45 AC 103 ms
52,624 KB
testcase_46 AC 193 ms
65,964 KB
testcase_47 AC 99 ms
53,336 KB
testcase_48 AC 202 ms
63,504 KB
testcase_49 AC 31 ms
38,024 KB
testcase_50 AC 32 ms
38,192 KB
testcase_51 AC 113 ms
54,348 KB
testcase_52 AC 26 ms
37,188 KB
testcase_53 AC 45 ms
42,232 KB
testcase_54 AC 22 ms
35,712 KB
testcase_55 AC 23 ms
35,840 KB
testcase_56 AC 22 ms
35,584 KB
testcase_57 AC 22 ms
35,840 KB
testcase_58 AC 22 ms
35,840 KB
testcase_59 AC 22 ms
35,712 KB
testcase_60 AC 23 ms
35,584 KB
testcase_61 AC 22 ms
35,840 KB
testcase_62 AC 22 ms
35,584 KB
testcase_63 AC 22 ms
35,712 KB
testcase_64 AC 22 ms
35,840 KB
testcase_65 AC 23 ms
35,712 KB
testcase_66 AC 23 ms
35,584 KB
testcase_67 AC 23 ms
35,584 KB
testcase_68 AC 23 ms
35,712 KB
testcase_69 AC 25 ms
36,096 KB
testcase_70 AC 24 ms
36,224 KB
testcase_71 AC 25 ms
36,352 KB
testcase_72 AC 24 ms
36,096 KB
testcase_73 AC 24 ms
35,968 KB
testcase_74 AC 24 ms
36,096 KB
testcase_75 AC 25 ms
36,224 KB
testcase_76 AC 150 ms
58,216 KB
testcase_77 AC 149 ms
56,288 KB
testcase_78 AC 27 ms
37,076 KB
testcase_79 AC 313 ms
73,884 KB
testcase_80 AC 177 ms
56,512 KB
testcase_81 AC 82 ms
49,668 KB
testcase_82 AC 408 ms
78,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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<short> vs;
    bool isvalid(int nxt){
      if(dist[vs.back()][nxt]<0) return false;
      if(count(vs.begin(),vs.end(),nxt)) return false;
      return true;
    }
    D len;
    bool operator<(const Path &o)const{
      if(len!=o.len) return len<o.len;
      if(vs.size()!=o.vs.size()) 
        return vs.size()<o.vs.size();
      return vs<o.vs;
    };
    bool operator>(const Path &o)const{
      if(len!=o.len) return len>o.len;
      if(vs.size()!=o.vs.size()) 
        return vs.size()>o.vs.size();
      return vs>o.vs;
    };
  };

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

  auto push=[&](Path p){
    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();

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

    for(int u:G[v]){
      if(!p.isvalid(u)) continue;
      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<<endl;
      continue;
    }
    cout<<dp[y].begin()->len<<endl;
    dp[y].erase(dp[y].begin());
  }
  return 0;
}
0