結果

問題 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,867 ms
コンパイル使用メモリ 223,128 KB
実行使用メモリ 211,332 KB
最終ジャッジ日時 2023-08-02 22:18:01
合計ジャッジ時間 12,564 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
35,436 KB
testcase_01 AC 12 ms
35,556 KB
testcase_02 AC 12 ms
35,556 KB
testcase_03 AC 11 ms
35,364 KB
testcase_04 AC 662 ms
198,236 KB
testcase_05 WA -
testcase_06 AC 90 ms
51,312 KB
testcase_07 AC 133 ms
58,116 KB
testcase_08 AC 48 ms
43,756 KB
testcase_09 AC 145 ms
58,844 KB
testcase_10 AC 17 ms
37,024 KB
testcase_11 AC 16 ms
36,248 KB
testcase_12 AC 13 ms
36,036 KB
testcase_13 AC 221 ms
66,588 KB
testcase_14 AC 41 ms
42,072 KB
testcase_15 AC 49 ms
43,064 KB
testcase_16 AC 29 ms
40,136 KB
testcase_17 AC 30 ms
39,480 KB
testcase_18 AC 21 ms
38,052 KB
testcase_19 AC 297 ms
74,136 KB
testcase_20 AC 400 ms
87,416 KB
testcase_21 AC 152 ms
59,260 KB
testcase_22 AC 35 ms
41,768 KB
testcase_23 AC 416 ms
80,464 KB
testcase_24 AC 56 ms
49,080 KB
testcase_25 AC 135 ms
62,232 KB
testcase_26 AC 95 ms
62,864 KB
testcase_27 AC 94 ms
62,644 KB
testcase_28 AC 95 ms
62,240 KB
testcase_29 AC 15 ms
36,388 KB
testcase_30 AC 12 ms
35,648 KB
testcase_31 AC 12 ms
35,504 KB
testcase_32 AC 12 ms
35,428 KB
testcase_33 AC 12 ms
35,508 KB
testcase_34 AC 12 ms
35,440 KB
testcase_35 AC 12 ms
35,544 KB
testcase_36 AC 12 ms
35,524 KB
testcase_37 AC 108 ms
51,456 KB
testcase_38 AC 37 ms
41,164 KB
testcase_39 AC 12 ms
35,540 KB
testcase_40 AC 15 ms
36,340 KB
testcase_41 AC 36 ms
40,432 KB
testcase_42 AC 59 ms
43,992 KB
testcase_43 AC 40 ms
42,180 KB
testcase_44 AC 177 ms
64,572 KB
testcase_45 AC 100 ms
52,288 KB
testcase_46 AC 201 ms
65,752 KB
testcase_47 AC 97 ms
53,716 KB
testcase_48 AC 193 ms
64,096 KB
testcase_49 AC 20 ms
37,640 KB
testcase_50 AC 21 ms
37,684 KB
testcase_51 AC 116 ms
54,116 KB
testcase_52 AC 16 ms
36,816 KB
testcase_53 AC 36 ms
42,064 KB
testcase_54 AC 12 ms
35,436 KB
testcase_55 AC 12 ms
35,404 KB
testcase_56 AC 11 ms
35,508 KB
testcase_57 AC 12 ms
35,628 KB
testcase_58 AC 12 ms
35,376 KB
testcase_59 AC 12 ms
35,504 KB
testcase_60 AC 12 ms
35,548 KB
testcase_61 AC 12 ms
35,616 KB
testcase_62 AC 11 ms
35,364 KB
testcase_63 AC 12 ms
35,376 KB
testcase_64 AC 12 ms
35,500 KB
testcase_65 AC 12 ms
35,432 KB
testcase_66 AC 11 ms
35,436 KB
testcase_67 AC 12 ms
35,544 KB
testcase_68 AC 12 ms
35,436 KB
testcase_69 AC 13 ms
35,796 KB
testcase_70 AC 14 ms
35,736 KB
testcase_71 AC 14 ms
35,924 KB
testcase_72 AC 12 ms
35,636 KB
testcase_73 AC 13 ms
35,788 KB
testcase_74 AC 14 ms
36,068 KB
testcase_75 AC 15 ms
35,932 KB
testcase_76 AC 145 ms
57,688 KB
testcase_77 AC 144 ms
55,888 KB
testcase_78 AC 18 ms
36,640 KB
testcase_79 AC 303 ms
73,640 KB
testcase_80 AC 167 ms
56,120 KB
testcase_81 AC 86 ms
49,808 KB
testcase_82 AC 410 ms
78,480 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