#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
using ll = long long;
const double INF = 1e16 + 7;
vector<vector<pair<int, double>>> adj;
vector<bool> vis;
void dfs(int k, int& H)
{
if (k == H || vis[k])
return;
vis[k] = 1;
for (auto i : adj[k])
dfs(i.F, H);
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr)
{
adj.resize(N);
vis.resize(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]);
}
dfs(0, H);
vector<vector<double>> dist(K + 1, vector<double>(N, INF));
for (int i = 0; i < N; i++)
if (arr[i] == 0 && vis[i])
for (int j = 0; j <= K; j++)
dist[j][i] = 0;
for (int i = 0; i <= K; i++)
{
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> PQ;
dist[i][0] = 0;
for (int j = 0; j < N; j++)
if (dist[i][j] == 0)
PQ.emplace(0, j);
while (!PQ.empty())
{
int u;
double d;
tie(d, u) = PQ.top();
PQ.pop();
if (d != dist[i][u] || u == H)
continue;
for (auto k : adj[u])
{
int v;
double w;
tie(v, w) = k;
bool flag = false;
if (dist[i][v] > dist[i][u] + w)
{
dist[i][v] = dist[i][u] + w;
flag = 1;
}
if (i > 0 && arr[v] == 2 && dist[i][v] > (dist[i - 1][u] + w) / 2.0)
{
dist[i][v] = (dist[i - 1][u] + w) / 2.0;
flag = 1;
}
if (flag)
PQ.emplace(dist[i][v], v);
}
}
}
return (dist[K][H] == INF ? -1 : dist[K][H]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
1000 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
1204 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
22712 KB |
Correct. |
2 |
Incorrect |
154 ms |
2000 KB |
Wrong Answer. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
1128 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
1288 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
1028 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
809 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |