結果

問題 No.1069 電柱 / Pole (Hard)
ユーザー どららどらら
提出日時 2020-05-30 00:22:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,643 bytes
コンパイル時間 1,793 ms
コンパイル使用メモリ 185,440 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-24 05:20:30
合計ジャッジ時間 3,623 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 7 ms
6,944 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 4 ms
6,944 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 8 ms
6,940 KB
testcase_21 AC 7 ms
6,940 KB
testcase_22 WA -
testcase_23 AC 8 ms
6,940 KB
testcase_24 WA -
testcase_25 AC 9 ms
6,940 KB
testcase_26 AC 7 ms
6,940 KB
testcase_27 AC 7 ms
6,940 KB
testcase_28 AC 7 ms
6,940 KB
testcase_29 AC 4 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 2 ms
6,940 KB
testcase_36 WA -
testcase_37 AC 3 ms
6,944 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 5 ms
6,940 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 8 ms
6,940 KB
testcase_46 WA -
testcase_47 AC 8 ms
6,940 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 3 ms
6,944 KB
testcase_51 WA -
testcase_52 AC 3 ms
6,940 KB
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 AC 2 ms
6,940 KB
testcase_57 WA -
testcase_58 AC 2 ms
6,944 KB
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 AC 1 ms
6,944 KB
testcase_63 AC 2 ms
6,940 KB
testcase_64 WA -
testcase_65 AC 2 ms
6,940 KB
testcase_66 WA -
testcase_67 AC 1 ms
6,940 KB
testcase_68 WA -
testcase_69 AC 4 ms
6,940 KB
testcase_70 AC 4 ms
6,944 KB
testcase_71 AC 5 ms
6,944 KB
testcase_72 AC 3 ms
6,944 KB
testcase_73 AC 4 ms
6,940 KB
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 AC 7 ms
6,940 KB
testcase_80 WA -
testcase_81 AC 9 ms
6,940 KB
testcase_82 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

template <class W>
class kShortestPath {
  struct edge {
    int src, dst;
    W w;
    edge(int src, int dst, W w) : src(src), dst(dst), w(w) {}
  };
  struct state {
    int src, dst;
    int plv;
    W wsum;
    state(int src, int dst, int plv, W wsum)
        : src(src), dst(dst), plv(plv), wsum(wsum) {}
    bool operator<(const state& that) const { return wsum > that.wsum; }
  };

  std::vector<std::vector<edge>> G;

 public:
  kShortestPath(int n) : G(n) {}
  void add_edge(int a, int b, W w) { G[a].emplace_back(edge(a, b, w)); }

  std::vector<double> getkthShortestPath(int s, int t, int k) {
    std::vector<std::vector<state>> dist(G.size());
    std::priority_queue<state> que;
    que.push(state(-1, s, -1, 0));
    while (!que.empty()) {
      state e = que.top();
      que.pop();
      if (dist[e.dst].size() >= k) continue;
      dist[e.dst].emplace_back(e);
      for (const edge& f : G[e.dst]) {
        que.push(state(f.src, f.dst, dist[e.dst].size() - 1, f.w + e.wsum));
      }
    }

    if (k > dist[t].size()) return std::vector<double>();

    vector<double> ret;
    rep(i,dist[t].size()){
      //simple path check
      map<int,int> m;
      int lv = i;
      int now = t;
      m[now] = 1;
      bool flg = true;
      while (true) {
        if(now == s && lv == 0) break;
        int plv = dist[now][lv].plv;
        int prev = dist[now][lv].src;
        
        if(m.count(prev) == 1){
          flg = false;
          break;
        }
        m[prev] = 1;
        lv = plv;
        now = prev;
      }
      if(!flg) break;
      ret.push_back(dist[t][i].wsum);
    }
    return ret;
  }
};

int main(){
  int N, M, K;
  cin >> N >> M >> K;
  int X, Y;
  cin >> X >> Y;
  vector<pair<int,int>> v;
  v.emplace_back(0,0);
  rep(i,N){
    int p, q;
    cin >> p >> q;
    v.emplace_back(p,q);
  }

  kShortestPath<double> ksp(N+1);
  rep(i,M){
    int p, q;
    cin >> p >> q;
    
    double px = v[p].first;
    double py = v[p].second;
    double qx = v[q].first;
    double qy = v[q].second;
    double dist = sqrt((px-qx)*(px-qx) + (py-qy)*(py-qy));

    ksp.add_edge(p, q, dist);
    ksp.add_edge(q, p, dist);
  }

  vector<double> ret = ksp.getkthShortestPath(X, Y, K);
  rep(i,K){
    if(i<ret.size()){
      printf("%.12lf\n", ret[i]);
    }else{
      cout << -1 << endl;
    }
  }
  return 0;
}

0