# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
978145 | math_rabbit_1028 | Cyberland (APIO23_cyberland) | C++17 | 261 ms | 13276 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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
int n, m, k, h;
vector<pll> adj[101010];
int ch[101010];
void DFS(int v) {
if (ch[v]) return;
ch[v] = 1;
for (int i = 0; i < adj[v].size(); i++) {
int u = adj[v][i].first;
DFS(u);
}
}
ll dis[101010];
priority_queue<pll> pq;
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
n = N; m = M; k = K; h = H;
for (int i = 0; i < m; i++) {
adj[x[i]].push_back({y[i], c[i]});
adj[y[i]].push_back({x[i], c[i]});
}
for (int i = 0; i < n; i++) ch[i] = 0;
DFS(0);
dis[0] = 0;
pq.push({-dis[0], 0});
for (int i = 0; i < n; i++) {
if (arr[i] == 0 && ch[i] == 1) {
dis[i] = 0;
pq.push({-dis[i], i});
}
else {
dis[i] = 1e18;
}
}
while (!pq.empty()) {
int v = pq.top().second; ll w = -pq.top().first;
pq.pop();
if (dis[v] < w) continue;
for (int i = 0; i < adj[v].size(); i++) {
int u = adj[v][i].first; ll ww = adj[v][i].second;
if (dis[u] > w + ww) {
dis[u] = w + ww;
pq.push({-dis[u], u});
}
}
}
if (dis[h] >= 1e18) return -1;
else return dis[h];
}
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... |