# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
756121 | yellowtoad | Cyberland (APIO23_cyberland) | C++17 | 1646 ms | 127124 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "cyberland.h"
#include <iostream>
#include <vector>
#include <queue>
#define f first
#define s second
using namespace std;
long long n, m, k, h, arr[100010];
long double dist[75][100010], minn;
bool vis[100010];
vector<pair<int,long long>> edge[100010];
priority_queue<pair<long double,int>,vector<pair<long double,int>>,greater<pair<long double,int>>> pq;
void dfs(int u) {
if (arr[u] == 0) dist[0][u] = 0;
vis[u] = 1;
for (int i = 0; i < edge[u].size(); i++) if (!vis[edge[u][i].f]) dfs(edge[u][i].f);
}
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) {
n = N; m = M; k = min(K,70); h = H; minn = 1e18;
for (int i = 0; i < n; i++) arr[i] = ARR[i];
for (int i = 0; i < n; i++) edge[i].clear();
for (int i = 0; i < m; i++) {
edge[x[i]].push_back({y[i],c[i]});
edge[y[i]].push_back({x[i],c[i]});
}
for (int i = 0; i <= k; i++) for (int j = 0; j < n; j++) dist[i][j] = 1e18;
for (int i = 0; i < n; i++) vis[i] = 0;
vis[h] = 1;
dfs(0);
dist[0][0] = 0;
for (int i = 0; i <= k; i++) {
for (int j = 0; j < n; j++) if (dist[i][j] != 1e18) pq.push({dist[i][j],j});
for (int i = 0; i < n; i++) vis[i] = 0;
vis[h] = 1;
while (pq.size()) {
int u = pq.top().s;
pq.pop();
if (vis[u]) continue;
vis[u] = 1;
for (int j = 0; j < edge[u].size(); j++) {
if (dist[i][u]+edge[u][j].s < dist[i][edge[u][j].f]) {
dist[i][edge[u][j].f] = dist[i][u]+edge[u][j].s;
pq.push({dist[i][edge[u][j].f],edge[u][j].f});
}
if (arr[edge[u][j].f] == 2) dist[i+1][edge[u][j].f] = min(dist[i+1][edge[u][j].f],(dist[i][u]+edge[u][j].s)/2);
}
}
}
for (int i = 0; i <= k; i++) minn = min(minn,dist[i][h]);
if (minn == 1e18) return -1;
else return minn;
}
Compilation message (stderr)
# | 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... |