Submission #1153348

#TimeUsernameProblemLanguageResultExecution timeMemory
1153348TroySerCyberland (APIO23_cyberland)C++20
15 / 100
54 ms13124 KiB
#include <bits/stdc++.h> #include "cyberland.h" #include <vector> using namespace std; using ll = long long; const ll INF = 1e15; vector<vector<ll> > adjList; map<pair<ll, ll>, ll> weightMat; double dijkstras(ll startingNode, vector<int> &A) { ll N = adjList.size(); priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > pq; pq.push({0.0, startingNode}); vector<ll> distances(N, INF); distances[startingNode] = 0.0; 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}); } } } ll minimumPossible = INF; for (ll i = 0; i < N; i++) { if (A[i] == 0 || i == 0) minimumPossible = min(minimumPossible, distances[i]); } return (double)(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]}] = (double)c[i]; weightMat[{y[i], x[i]}] = (double)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...