結果

問題 No.1069 電柱 / Pole (Hard)
ユーザー m_9719m_9719
提出日時 2020-05-29 22:52:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,296 bytes
コンパイル時間 1,722 ms
コンパイル使用メモリ 177,696 KB
実行使用メモリ 817,428 KB
最終ジャッジ日時 2024-04-24 05:10:47
合計ジャッジ時間 4,876 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(998244353)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef pair<double,int> PDI;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct State {
    int n; double w;
    State(int n, double w) :
	n(n), w(w) {}
    bool operator < (const State &s) const {
	return w > s.w;
    }
};

struct Edge {
    int n; double w;
    Edge (int n, double w) :
	n(n), w(w) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
vector<double> ans;

int k_shortestPath(const Graph &g, int s, int e, int k) {
    int N = g.size();
    double dist[N];
    bool visited[N];
    for (int i = 0; i <= N; ++i) dist[i] = (double)LINF;
    dist[e] = 0.0;
    memset(visited, false, sizeof(visited));
    priority_queue<State> Q;
    Q.push(State(e, 0.0));
    while (!Q.empty()) {
			State cr = Q.top(); Q.pop();
			if (visited[cr.n]) continue;
			visited[cr.n] = true;
			for (int i = 0; i < g[cr.n].size(); ++i) {
		    Edge edg = g[cr.n][i];
		    if (visited[edg.n]) continue;
		    if (dist[edg.n] > cr.w + edg.w) {
					dist[edg.n] = cr.w + edg.w;
					Q.push(State(edg.n, cr.w + edg.w));
				}
			}
  	}
		// cerr<<R.top().w<<endl;
    int cnt = 0; // ゴールカウント
    priority_queue<State> R;
    /* priority_queue Rは
     * [それまでの距離+そのノードからゴールまでの距離]
     * でソートされる。
     * これによりゴールに近い状態から取り出される
     */
    R.push(State(1, 0.0 + dist[s]));
    while (!R.empty()) {
			State cr = R.top(); R.pop();
			cr.w -= dist[cr.n]; // cr.wをそれまでの距離に戻す
			if (cr.n == e && ++cnt <= k) ans.PB(cr.w);
			// cerr<<R.size()<<endl;
			if(cr.n == e && cnt==k+1) return k;
			for (int i = 0; i < g[cr.n].size(); ++i) {
			    Edge edg = g[cr.n][i];
			    R.push(State(edg.n, cr.w + edg.w + dist[edg.n]));
			}
			if(R.size()==1) return -1;
    }
    return -1;
}

int main() {
	int n,m,k; cin>>n>>m>>k;
	Graph g(n);
	int x,y; cin>>x>>y; x--; y--;
	vector<PDD> t;
	rep(i,n){
		double p,q; cin>>p>>q;
		t.PB(MP(p,q));
	}
	rep(i,m){
		int p,q; cin>>p>>q; p--; q--;
		double d=pow(pow(t[p].first-t[q].first,2.0)+pow(t[p].second-t[q].second,2.0),0.50);
		g[p].PB(Edge(q,d)); g[q].PB(Edge(p,d));
	}
	int ret=k_shortestPath(g, x, y, k);
	rep(i,ans.size()) cout<<ans[i]<<endl;
	rep(i,k-ans.size()) cout<<-1<<endl;


    // printf("%d\n", k_shortestPath(g, x, y, k));
}
0