This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> v2pii;
int main(){
int K, N, M, O, a, b, t;
cin >> K >> N >> M >> O;
v2pii listaAdy(N);
for(int i = 0; i < M; ++i){
cin >> a >> b >> t;
listaAdy[a].push_back({b, t});
}
vi dist(N, 1e9+7);
dist[0] = 0;
pii inicio = {-0, 0};
priority_queue<pii> PQ;
PQ.push(inicio);
while(!PQ.empty()){
pii act = PQ.top(); PQ.pop();
int distAct = -1*act.first;
int nodo = act.second;
if(distAct > dist[nodo]) continue;
dist[nodo] = distAct;
for(pii vecino: listaAdy[nodo]){
PQ.push({-1*(distAct+vecino.second), vecino.first});
}
}
while(O--){
cin >> a >> b;
cout << dist[b] << endl;
}
return 0;
}
# | 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... |