Submission #1201408

#TimeUsernameProblemLanguageResultExecution timeMemory
1201408zh_hCyberland (APIO23_cyberland)C++17
44 / 100
46 ms9288 KiB
#include<bits/stdc++.h> #define pb push_back using namespace std; double solve (int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { vector<vector<pair<int, double>>> edge(N); for (int i = 0; i < M; i ++) { edge[x[i]].pb({y[i], c[i]}); edge[y[i]].pb({x[i], c[i]}); } vector<bool> visited(N, false); queue<int> q; q.push(0); while (!q.empty()) { int v = q.front(); q.pop(); if (v == H) continue; for (auto [u, w] : edge[v]) { if (visited[u]) continue; visited[u] = true; q.push(u); } } priority_queue<pair<double, int>> pq; vector<double> dist(N, 1e19); dist[0] = 0; pq.push({0, 0}); // cout << "zeros: "; for (int i = 0; i < N; i ++) { if (arr[i] == 0 && visited[i]) { // cout << i << " "; pq.push({0, i}); dist[i] = 0; } } // cout << endl; visited.clear(); visited.resize(N, false); while (!pq.empty()) { int v = pq.top().second; pq.pop(); // cout << v << endl; visited[v] = true; // priority_queue<pair<double, int>> pq_temp = pq; // while (!pq_temp.empty()) { // cout << pq_temp.top().first << " " << pq_temp.top().second << endl; // pq_temp.pop(); // } // cout << endl; // for (auto i : visited) {cout << i << " ";} cout << endl; for (auto [u, w] : edge[v]) { if (visited[u]) continue; if (dist[v] + w < dist[u]) { dist[u] = dist[v] + w; // if (arr[u] == 0) {dist[u] = 0;} pq.push({ (dist[u]*(-1)) , u}); } } } // if (dist[0] == 1e19) {return (double)-1;} // return (double)dist[0]; if (dist[H] == 1e19) {return (double)-1;} return (double)dist[H]; }
#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...