이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
void dijkstra(int a,vector<vector<pair<int,int>>>& g,vector<int>& dist){
for(int i=0;i<dist.size();i++)dist[i]=1e18;
dist[a]=0;
priority_queue<pair<int,int>> pq;
pq.push({0,a});
while(pq.size()){
int u=pq.top().second,d=-pq.top().first;
pq.pop();
if(d>dist[u])continue;
for(auto v:g[u]){
if(dist[v.first]>dist[u]+v.second){
dist[v.first]=dist[u]+v.second;
pq.push({-dist[v.first],v.first});
}
}
}
}
signed main(){
int n,m,o,k,x,y,w;
cin>>k>>n>>m>>o;
vector<vector<pair<int,int>>> g(n,vector<pair<int,int>>());
vector<long long> dist(n,1e18);
while(m--){
cin>>x>>y>>w;
//x--;y--;
g[x].push_back({y,w});
g[y].push_back({x,w});
}
dijkstra(0,g,dist);
while(o--){
cin>>x>>y;
if(dist[y]==1e18)cout<<-1<<'\n';
else cout<<dist[y]<<'\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
toll.cpp: In function 'void dijkstra(long long int, std::vector<std::vector<std::pair<long long int, long long int> > >&, std::vector<long long int>&)':
toll.cpp:7:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | for(int i=0;i<dist.size();i++)dist[i]=1e18;
| ~^~~~~~~~~~~~
# | 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... |