답안 #737712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737712 2023-05-07T15:06:39 Z lalig777 Autobus (COCI22_autobus) C++14
0 / 70
20 ms 364 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

long long int Dijkstra(int a, int b, vector<vector<pair<int, int>>>&listaAdy, int k) {
    int N=(int)listaAdy.size();
    vector<long long int>distancia(N, 1e18);
    vector<int>usado(N, 0);
    distancia[a]=0;
    priority_queue<pair<long long int, int>>pq;
    pq.push(make_pair(0, a));
    while(!pq.empty()) {
        int nodo=pq.top().second;
        long long int distanciaAlt=-pq.top().first;
        pq.pop();
        if (distanciaAlt>distancia[nodo] or usado[nodo]>=k) continue;
        for (pair<int, int> vecino: listaAdy[nodo]) {
            int nodoVecino=vecino.first;
            long long int costeVecino=vecino.second;
            if (distancia[nodoVecino]>distancia[nodo]+costeVecino) {
                distancia[nodoVecino]=distancia[nodo]+costeVecino;
                pq.push(make_pair(-distancia[nodoVecino], nodoVecino));
                usado[nodoVecino]=usado[nodo]+1;
            }
        }
    }return distancia[b];
}

int main(){
    int n, m, a, b, t, k, q;
    cin>>n>>m;
    vector<vector<pair<int, int>>>listaAdy(n);
    for (int i=0; i<m; i++){
        cin>>a>>b>>t;
        listaAdy[a-1].push_back(make_pair(b-1, t));
    }cin>>k>>q;
    for (int i=0; i<q; i++){
        cin>>a>>b;
        long long int res=Dijkstra(a-1, b-1, listaAdy, k);
        if (res==1000000000000000000) cout<<-1<<endl;
        else cout<<res<<endl;
    }return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 340 KB Output is correct
2 Incorrect 20 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -