Submission #1153338

#TimeUsernameProblemLanguageResultExecution timeMemory
1153338TroySerCyberland (APIO23_cyberland)C++20
0 / 100
35 ms13124 KiB
#include <bits/stdc++.h> #include "cyberland.h" #include <vector> using namespace std; using ll = long long; const ll INF = 1e18; vector<vector<ll> > adjList; map<pair<ll, ll>, ll> weightMat; double dijkstras(ll startingNode, vector<int> &A) { ll N = adjList.size(); priority_queue<pair<double, ll>, vector<pair<double, ll> >, greater<pair<double, ll> > > pq; pq.push({0.0, startingNode}); vector<double> distances(N, (double)INF); while (!pq.empty()) { auto [currentDistance, currentNode] = pq.top(); pq.pop(); if (currentDistance >= distances[currentNode]) { continue; } for (ll v: adjList[currentNode]) { if (currentDistance + weightMat[{currentNode, v}] < distances[v]) { distances[v] = currentDistance + weightMat[{currentNode, v}]; pq.push({distances[v], v}); } } } double minimumPossible = INF; for (ll i = 0; i < N; i++) { if (A[i] == 0 || i == 0) minimumPossible = min(minimumPossible, distances[i]); } return minimumPossible; } double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { adjList.clear(); weightMat.clear(); adjList.resize(N); for (ll i = 0; i < M; i++) { adjList[x[i]].push_back(y[i]); adjList[y[i]].push_back(x[i]); weightMat[{x[i], y[i]}] = c[i]; weightMat[{y[i], x[i]}] = c[i]; } double response = dijkstras(H, arr); if (response >= INF) { return -1.0; } else { return response; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...