Submission #967027

#TimeUsernameProblemLanguageResultExecution timeMemory
967027Batorgil952사이버랜드 (APIO23_cyberland)C++17
15 / 100
1149 ms23592 KiB
#include "cyberland.h"
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

using namespace std;

const int N=1e5+5;
vector< pair< int, int > > v[N];
double T[N][35];

double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
	priority_queue< pair< double, pair< ll, ll > >, vector< pair< double, pair< ll, ll > > >, greater< pair< double, pair< ll, ll > > > > q;
	int ind=1;
	
	for(int i=0; i<N; i++){
		v[i].clear();
		for(int j=0; j<=30; j++){
			T[i][j]=1000000000000000000.0;
		}
	}
	for(int i=0; i<M; i++){
		v[x[i]].pb(mp(y[i], c[i]));
		v[y[i]].pb(mp(x[i], c[i]));
	}
	q.push(mp(0, mp(0, 0)));
	for(int i=0; i<=30; i++){
		T[0][i]=0;
	}
	while(!q.empty()){
		int x=q.top().ss.ff;
		int z=q.top().ss.ss;
		double y=q.top().ff;
		q.pop();
		if(x==H) ind=0;
		if(y>T[x][z] || z>K){
			continue;
		}
		int vn=v[x].size();
		for(int i=0; i<vn; i++){
			if(arr[v[x][i].ff]==1){
				if(T[v[x][i].ff][z]>T[x][z]+v[x][i].ss*1.0){
					T[v[x][i].ff][z]=T[x][z]+v[x][i].ss*1.0;
					q.push(mp(T[v[x][i].ff][z], mp(v[x][i].ff, z)));
				}
			}
			if(arr[v[x][i].ff]==2){
				if(T[v[x][i].ff][z+1]>(T[x][z]+v[x][i].ss*1.0)/2.0){
					T[v[x][i].ff][z+1]=(T[x][z]+v[x][i].ss*1.0)/2.0;
					q.push(mp(T[v[x][i].ff][z+1], mp(v[x][i].ff, z+1)));
				}
				if(T[v[x][i].ff][z]>T[x][z]+v[x][i].ss*1.0){
					T[v[x][i].ff][z]=T[x][z]+v[x][i].ss*1.0;
					q.push(mp(T[v[x][i].ff][z], mp(v[x][i].ff, z)));
				}
			}
			if(arr[v[x][i].ff]==0){
				if(T[v[x][i].ff][z]>0.0){
					T[v[x][i].ff][z]=0.0;
					q.push(mp(T[v[x][i].ff][z], mp(v[x][i].ff, z)));
				}
			}
		}
	}
	
	if(ind==1) return -1;
	double ans=T[H][0];
	for(int i=1; i<=K; i++){
		ans=min(ans, T[H][i]);
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...