이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
using namespace std;
using ll = int; using pii = pair<ll,ll>;
using ld = double; using vi = vector<int>;
const ld INF = 1e18;
double solve(int N, int M, int K, int H, vi x, vi y, vi c, vi arr) {
ld tmin[N][K+1];
ld tminT[N][K+1]; //temporary
bool dfsf[N];
for (ll i=0;i<N;i++) {
dfsf[i]=0;
for (ll k=0;k<=K;k++) {
tmin[i][k]=INF;
tminT[i][k]=INF;
}
}
vector<pii> adj[N]; //vertex,cost
for (ll i=0;i<M;i++) {
adj[x[i]].push_back({y[i],c[i]});
adj[y[i]].push_back({x[i],c[i]});
}
stack<int> s;
s.push(0);
while (!s.empty()) {
ll x0 = s.top(); s.pop();
if (!dfsf[x0]) {
dfsf[x0]=1;
if (x0==H) {
continue;
}
for (pii p0: adj[x0]) {
s.push(p0.first);
}
}
}
if (!dfsf[H]) {
return -1.0;
}
priority_queue<pair<ld,ll>> pq[K+1]; //{#k,{time,position}}
pq[0].push({0.0,0});
for (ll i=0;i<N;i++) {
if (dfsf[i] && (arr[i]==0)) {
pq[0].push({0.0,i});
}
}
for (ll k=0;k<=K;k++) {
if (k != 0) {
for (ll i=0;i<N;i++) {
if (tminT[i][k]!=INF) {
pq[k].push({tminT[i][k],i});
}
}
}
while (!pq[k].empty()) {
auto A = pq[k].top(); pq[k].pop();
ld T = A.first; ll x0 = A.second;
if (arr[x0]==0 && T != 0.0) {
continue;
}
if (tmin[x0][k]<=(T+1e-10)) {
continue;
}
tmin[x0][k]=T;
if (x0==H) {
continue;
}
for (pii p0: adj[x0]) {
ll y0 = p0.first; ld ce = p0.second;
if (tmin[y0][k]>=(ce+T+1e-10)) {
pq[k].push({ce+T,y0});
}
if (arr[x0]==2 && k<K) {
tminT[y0][k+1]=min(tminT[y0][k+1],ce+T/2);
}
}
}
}
ld ans = INF;
for (ll k=0;k<=K;k++) {
ans = min(ans,tmin[H][k]);
}
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... |