Submission #976551

#TimeUsernameProblemLanguageResultExecution timeMemory
976551Elliot_7002Cyberland (APIO23_cyberland)C++17
0 / 100
25 ms10588 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define INF 1e15 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; } }

Compilation message (stderr)

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:4:13: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+15' to '2147483647' [-Woverflow]
    4 | #define INF 1e15
      |             ^~~~
cyberland.cpp:66:20: note: in expansion of macro 'INF'
   66 |         int mini = INF;
      |                    ^~~
#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...