Submission #976552

#TimeUsernameProblemLanguageResultExecution timeMemory
976552Elliot_7002Cyberland (APIO23_cyberland)C++17
0 / 100
24 ms10692 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define INF 1e9 vector<vector<pair<int,int>>> adj; vector<double> distances; vector<bool> visited; priority_queue<int> q; void dijkstra(int source) { visited[source] = true; distances[source] = 0; q.push(source); while(!q.empty()){ int a = q.top(); q.pop(); if(visited[a]){ continue; } for(auto neigh: adj[a]){ if(distances[a] + neigh.second < distances[neigh.first]){ distances[neigh.first] = distances[a] + neigh.second; q.push(neigh.second); } } } } bool dfs_hunt(int node, int target){ bool found = false; if(visited[node]){ return found; } if(node == target){ found = true; return found; } for(auto i : adj[node]){ found = dfs_hunt(i.first,target); if(found){ return found; } } return found; } double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){ adj.clear(); adj.resize(n); visited.clear(); visited.resize(n,false); 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++){ distances[i] = INF; } if(!dfs_hunt(0, h)){ return -1; } else{ visited.clear(); visited.resize(n,false); dijkstra(h); int mini = INF; for(int i = 0; i < n; i++){ if(arr[i] == 0){ if(distances[i] < mini){ mini = distances[i]; } } } return mini; } }
#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...