이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
const double INF = 1e18 + 7;
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr)
{
vector<vector<pair<int, double>>> adj(N);
for (int i = 0; i < M; i++)
{
adj[x[i]].emplace_back(y[i], c[i]);
adj[y[i]].emplace_back(x[i], c[i]);
}
vector<bool> vis(N);
queue<int> Q;
Q.push(0);
while (!Q.empty())
{
int u = Q.front();
Q.pop();
if (u == H)
continue;
for (pair<int, double> i : adj[u])
if (!vis[i.F])
{
vis[i.F] = 1;
Q.push(i.F);
}
}
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> PQ;
vector<vector<double>> dist(N, vector<double>(K + 1, INF));
for (int i = 0; i < N; i++)
if (vis[i] && arr[i] == 0)
{
dist[i][0] = 0;
PQ.emplace(0, i);
}
dist[0][0] = 0;
PQ.emplace(0, 0);
while (!PQ.empty())
{
double d;
int u;
tie(d, u) = PQ.top();
PQ.pop();
if (d != dist[u][0] || u == H)
continue;
for (pair<int, double> i : adj[u])
{
int v;
double w;
tie(v, w) = i;
if (dist[v][0] > dist[u][0] + w)
PQ.emplace(dist[v][0] = dist[u][0] + w, v);
}
}
for (int i = 1; i <= K; i++)
{
for (int j = 0; j < N; j++)
if (vis[j] && arr[j] == 0)
{
dist[j][i] = 0;
PQ.emplace(0, j);
}
dist[0][i] = 0;
PQ.emplace(0, 0);
while (!PQ.empty())
{
int u;
double d;
tie(d, u) = PQ.top();
PQ.pop();
if (d != dist[u][i] || u == H)
continue;
for (pair<int, double> j : adj[u])
{
int v;
double w;
tie(v, w) = j;
if (dist[v][i] > (dist[u][i - 1] + w) / 2.0 && arr[v] == 2)
PQ.emplace(dist[v][i] = (dist[u][i - 1] + w) / 2.0, v);
if (dist[v][i] > dist[u][i] + w)
PQ.emplace(dist[v][i] = dist[u][i] + w, v);
}
}
}
return (dist[H][K] == INF ? -1 : dist[H][K]);
}
# | 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... |