#include "cyberland.h"
#include "queue"
#include <vector>
using namespace std;
double eps = 1e-9;
vector<vector<pair<int, double>>> g;
vector<int> slv1(vector<int> arr, int n, int k, int h) {
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<>> que;
for (int i = 0; i < k; ++i) {
que.push({0, i});
}
vector<double> res(g.size(), 1e18);
while (!que.empty()) {
auto [prc, v] = que.top();
//cout << prc << ' ' << v << '\n';
que.pop();
if (v == h)
continue;
if (prc + eps > res[v])
continue;
res[v] = prc;
for (auto i : g[v])
que.push({prc + i.second, i.first});
}
vector<int> reska;
for (int i = 0; i < g.size(); ++i) {
if (res[i] < 1e17 and arr[i % n] == 0)
reska.push_back(i);
}
return reska;
}
double slv2(int n, int k, int h, vector<int> tork) {
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<>> que;
for (auto i : tork) {
que.push({0, i});
}
vector<double> res(g.size(), 1e18);
while (!que.empty()) {
auto [prc, v] = que.top();
que.pop();
if (prc > res[v])
continue;
res[v] = prc;
for (auto i : g[v])
que.push({prc + i.second, i.first});
}
return res[n * k - n + h];
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
K = min(K+1, 31);
int kn = K * N;
//cout << kn << '\n';
g.assign(kn, {});
double dv = 1;
for (int i = 0; i < M; ++i) {
for (int j = K - 1; j >= 0; --j) {
int a = x[i], b = y[i], tm = c[i];
int isa = arr[a];
a += j * N;
b += j * N;
g[a].push_back({b, tm / dv});
if (isa == 2) {
if (j + 1 != K)
g[a].push_back({b + N, tm * 2 / dv});
}
a = y[i], b = x[i], tm = c[i];
isa = arr[a];
a += j * N;
b += j * N;
g[a].push_back({b, tm / dv});
if (isa == 2) {
if (j + 1 != K)
g[a].push_back({b + N, tm * 2 / dv});
}
}
}
arr[0] = 0;
vector<int> tor2 = slv1(arr, N, K, H);
double res = slv2(N, K, H, tor2);
if (res > 1e17)
return -1;
return res;
}
Compilation message
cyberland.cpp: In function 'std::vector<int> slv1(std::vector<int>, int, int, int)':
cyberland.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, double> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i = 0; i < g.size(); ++i) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
140 ms |
452 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
172 ms |
4516 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
219 ms |
4488 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3060 ms |
201556 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
170 ms |
5048 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
187 ms |
5144 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2363 ms |
18232 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2302 ms |
18236 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |