Submission #737685

# Submission time Handle Problem Language Result Execution time Memory
737685 2023-05-07T14:41:53 Z Ariadna Autobus (COCI22_autobus) C++14
0 / 70
16 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;

int n, m;
vector < vector < pair < int, int > > > adj;

int dijkstra(int s, int f, int k) {
    vector < int > dist(n, INF);
    priority_queue < pair < int, pair < int, int > > > pq;
    dist[s] = 0;
    pq.push(make_pair(0, make_pair(s, 0)));
    
    while (!pq.empty()) {
        int d = -pq.top().first;
        int u = pq.top().second.first;
        int l = pq.top().second.second;
        pq.pop();
        if (l == k) continue;
        if (dist[u] != d) 
            continue;
        for (pair < int, int > vecino : adj[u]) {
            int v = vecino.first;
            int w = vecino.second;
            if (dist[v] > dist[u] + w) {
                dist[v] = dist[u] + w;
                pq.push(make_pair(-dist[v], make_pair(v, l + 1)));
            }
        }
    }
    if (dist[f] == INF) return -1;
    return dist[f];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n >> m;
    adj = vector < vector < pair < int, int > > >(n);
    while (m--) {
        int a, b, t;
        cin >> a >> b >> t;
        --a; --b;
        adj[a].push_back(make_pair(b, t));
    }
    int k, q;
    cin >> k >> q;
    while (q--) {
        int a, b;
        cin >> a >> b;
        cout << dijkstra(a - 1, b - 1, k) << '\n';
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 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 -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 340 KB Output is correct
2 Incorrect 16 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 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 -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 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 -