이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
//#include "stub.cpp"
using namespace std;
#define ll long long
//#define int ll
#define pb push_back
#define tt pair<int,pair<int,int>>
#define fr first
#define sc second.first
#define tr second.second
const ll N=1e5+5,INF=1e18;
double dist[N][33];
vector<pair<int,int>> g[N];
int a[N];
int used[N];
void djks(int x, int h, int n){
priority_queue<tt,vector<tt>,greater<tt>> pq;
//pq.push({0,{x,0}});
for(int i=0;i<n;i++){
if(used[i] && (i==0 || a[i]==0)){
pq.push({0,{i,0}});
dist[i][0]=0;
}
}
while(!pq.empty()){
tt tmp=pq.top();
pq.pop();
//double d=tmp.fr;
int cur=tmp.sc,t=tmp.tr;
if(cur==h) continue;
for(auto it: g[cur]){
if(dist[it.first][t]>dist[cur][t]+it.second){
dist[it.first][t]=dist[cur][t]+it.second;
pq.push({dist[it.first][t],{it.first,t}});
}
if(t==30) continue;
if(a[it.first]==2){
if(dist[it.first][t+1]>(dist[cur][t]+it.second)/2){
dist[it.first][t+1]=(dist[cur][t]+it.second)/2;
pq.push({dist[it.first][t+1],{it.first,t+1}});
}
}
}
}
}
void dfs(int x, int h){
if(x==h) return;
used[x]=1;
for(auto it: g[x]){
if(!used[it.first])
dfs(it.first,h);
}
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
for(int i=0;i<N;i++){
for(int j=0;j<=31;j++)
dist[i][j]=INF;
g[i].clear();
used[i]=0;
}
for(int i=0;i<M;i++){
g[x[i]].pb({y[i],c[i]});
g[y[i]].pb({x[i],c[i]});
}
for(int i=0;i<N;i++)
a[i]=arr[i];
dfs(0,H);
djks(0,H,N);
double ans=INF;
for(int i=0;i<=K;i++){
ans=min(ans,dist[H][i]);
}
if(ans==INF) return -1;
else return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |