이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
};
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]) {
distances[i] = 0;
Q.push({0, startIndex});
}
}
while(!Q.empty()) {
ll node = Q.top().second, dist = Q.top().first;
Q.pop();
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);
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();
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);
}
}
vector<ll> distances(N, LLONG_MAX);
dijkstra(graph, can, distances, arr, 0);
ll ans = distances[H] == LLONG_MAX ? -1 : distances[H];
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
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:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<node> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i = 0; i < graph.size(); i++) {
| ~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |