#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
const double INF = numeric_limits<double>::max();
double nonol(vector<vector<pair<int, int>>> g, int N, int M, int K, int H, vector<int> arr) {
vector<bool> used(N), ot(N);
function<void(int, int)> dfs = [&](int v, int cnt) {
assert(!used[v]);
used[v] = true;
for (auto [to, weight]: g[v]) {
if (!used[to]) {
if (arr[to] == 2 && cnt) {
ot[to] = true;
dfs(to, cnt - 1);
} else dfs(to, cnt);
}
}
};
vector<double> d(N + 1, INF);
d[0] = 0;
set<pair<double, int>> q;
q.emplace(d[0], 0);
while (!q.empty()) {
int nearest = q.begin()->second;
q.erase(q.begin());
for (auto [to, weight]: g[nearest]) {
double dis = d[nearest] + weight;
if (ot[to]) dis /= 2;
if (!arr[to]) dis = 0;
if (d[to] > dis) {
q.erase(pair{d[to], to});
d[to] = dis;
q.emplace(d[to], to);
}
}
}
if (d[H] == INF) d[H] = -1;
return d[H];
}
double s1(vector<vector<pair<int, int>>> g, int N, int M, int K, int H, vector<int> arr) {
double dis = INF;
bool can = false;
double zap;
int u;
for (auto [to, weight]: g[0]) {
if (to == H) {
dis = fmin(dis, weight);
} else can = true, zap = weight, u = to;
}
if (can) {
double w;
can = false;
for (auto [to, weight]: g[u]) {
if (to == H) can = true, w = weight;
}
if (can) {
if (arr[u] == 0) dis = fmin(dis, w);
else if (arr[u] == 1) dis = fmin(dis, w + zap);
else dis = fmin(dis, zap / 2. + w);
}
}
if (dis == INF) dis = -1;
return dis;
}
double s4(std::vector<int> x, std::vector<int> y, std::vector<int> c, int N, int M, int K, int H, vector<int> arr) {
vector<bool> ot(N);
int cnt = K;
for (int i = H - 1; i > 0; --i) {
if (arr[i] == 2 && cnt) cnt--, ot[i] = true;
}
cnt = K;
for (int i = H + 1; i < N; ++i) {
if (arr[i] == 2 && cnt) cnt--, ot[i] = true;
}
double dis = INF;
double tmp = 0;
for (int i = 0; i < H; ++i) {
tmp += c[i];
if (arr[i + 1] == 0) tmp = 0;
if (arr[i + 1] == 2) tmp /= 2;
}
dis = tmp;
tmp = 0;
bool flag = false;
for (int i = N - 1; i > H; --i) {
tmp += c[i - 1];
if (arr[i - 1] == 0) tmp = 0, flag = true;
if (arr[i - 1] == 2) tmp /= 2;
}
if (flag) dis = min(dis, tmp);
if (dis == INF) dis = -1;
return dis;
}
double yesnol(vector<vector<pair<int, int>>> g, int N, int M, int K, int H, vector<int> arr) {return -1;}
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
vector<vector<pair<int, int>>> g(N);
bool is2 = true;
for (int i = 0; i < M; ++i) {
g[x[i]].emplace_back(y[i], c[i]);
g[y[i]].emplace_back(x[i], c[i]);
if (x[i] != i + 1 || y[i] != i + 2) is2 = false;
}
if (N <= 3) return s1(g, N, M, K, H, arr);
else if (is2) return s4(x, y, c, N, M, K, H, arr);
else if (find(arr.begin(), arr.end(), 0LL) == arr.end()) return nonol(g, N, M, K, H, arr);
else return yesnol(g, N, M, K, H, arr);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
496 KB |
Correct. |
2 |
Correct |
16 ms |
440 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
652 KB |
Correct. |
2 |
Correct |
29 ms |
644 KB |
Correct. |
3 |
Correct |
26 ms |
644 KB |
Correct. |
4 |
Correct |
33 ms |
648 KB |
Correct. |
5 |
Correct |
29 ms |
648 KB |
Correct. |
6 |
Correct |
23 ms |
2020 KB |
Correct. |
7 |
Correct |
29 ms |
1952 KB |
Correct. |
8 |
Correct |
16 ms |
3676 KB |
Correct. |
9 |
Correct |
38 ms |
344 KB |
Correct. |
10 |
Correct |
27 ms |
536 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
612 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
8760 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
604 KB |
Correct. |
2 |
Correct |
26 ms |
600 KB |
Correct. |
3 |
Correct |
28 ms |
636 KB |
Correct. |
4 |
Correct |
23 ms |
1884 KB |
Correct. |
5 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
604 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
872 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
1260 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |