#include "cyberland.h"
#include <bits/stdc++.h>
#include <vector>
#define pll pair<ll, ll>
#define ll long long
using namespace std;
struct node {
ll v, w;
};
ll ed;
void dijkstra(vector<vector<node> >& graph, vector<bool>& can, vector<ll>& distances, vector<int>& t, ll startIndex) {
priority_queue<pll, vector<pll>, greater<> > Q;
distances[startIndex] = 0;
Q.push({0, startIndex});
for(int i = 0; i < graph.size(); i++) {
if(i == startIndex) continue;
if(t[i] == 0 && can[i]) {
//cout<<"I: "<<i<<endl;
distances[i] = 0;
Q.push({0, i});
}
}
while(!Q.empty()) {
ll node = Q.top().second, dist = Q.top().first;
Q.pop();
if(node == ed) continue;
if(distances[node] < dist) continue;
for(auto [v, w] : graph[node]) {
if(distances[node] + w < distances[v]) {
distances[v] = distances[node] + w;
Q.push({distances[v], v});
}
}
}
}
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
vector<vector<node> > graph(N);
ed = H;
for(int i = 0; i < M; i++) {
graph[x[i]].push_back({y[i], c[i]});
graph[y[i]].push_back({x[i], c[i]});
}
vector<bool> can(N, false);
vector<bool> visited(N, false);
queue<ll> Q;
Q.push(0);
visited[0] = true;
while(!Q.empty()) {
ll node = Q.front();
//cout<<node<<" <= "<<endl;
can[node] = true;
Q.pop();
for(auto [el, w] : graph[node]) {
if(el == H) continue;
if(visited[el]) continue;
visited[el] = true;
Q.push(el);
}
}
/* for(auto el : can) cout<<el<<" ";
cout<<endl;*/
vector<ll> distances(N, LLONG_MAX);
dijkstra(graph, can, distances, arr, 0);
ll ans = distances[H] == LLONG_MAX ? -1 : distances[H];
return ans;
}
Compilation message
cyberland.cpp: In function 'void dijkstra(std::vector<std::vector<node> >&, std::vector<bool>&, std::vector<long long int>&, std::vector<int>&, long long int)':
cyberland.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<node> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int i = 0; i < graph.size(); i++) {
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
856 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1112 KB |
Correct. |
2 |
Correct |
23 ms |
1372 KB |
Correct. |
3 |
Correct |
27 ms |
1296 KB |
Correct. |
4 |
Correct |
25 ms |
1328 KB |
Correct. |
5 |
Correct |
24 ms |
1220 KB |
Correct. |
6 |
Correct |
21 ms |
2196 KB |
Correct. |
7 |
Correct |
30 ms |
2164 KB |
Correct. |
8 |
Correct |
14 ms |
3164 KB |
Correct. |
9 |
Correct |
30 ms |
1196 KB |
Correct. |
10 |
Correct |
23 ms |
1264 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
1304 KB |
Correct. |
2 |
Correct |
25 ms |
1372 KB |
Correct. |
3 |
Correct |
22 ms |
1372 KB |
Correct. |
4 |
Correct |
24 ms |
1372 KB |
Correct. |
5 |
Correct |
24 ms |
1272 KB |
Correct. |
6 |
Correct |
5 ms |
1628 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
8084 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1116 KB |
Correct. |
2 |
Correct |
22 ms |
1360 KB |
Correct. |
3 |
Correct |
23 ms |
1352 KB |
Correct. |
4 |
Correct |
23 ms |
2120 KB |
Correct. |
5 |
Correct |
20 ms |
1112 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1284 KB |
Correct. |
2 |
Correct |
19 ms |
1508 KB |
Correct. |
3 |
Correct |
33 ms |
11088 KB |
Correct. |
4 |
Correct |
13 ms |
1972 KB |
Correct. |
5 |
Correct |
21 ms |
1368 KB |
Correct. |
6 |
Correct |
23 ms |
1876 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
1116 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
1112 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |