Submission #737728

# Submission time Handle Problem Language Result Execution time Memory
737728 2023-05-07T15:37:10 Z Ariadna Autobus (COCI22_autobus) C++14
15 / 70
82 ms 384 KB
#include <bits/stdc++.h>
#define ll long long int
 
using namespace std;
 
ll INF = 1e18;
 
int n, m;
vector < vector < pair < int, int > > > adj;
 
ll dijkstra(int s, int f, int k) {
    vector < pair < ll, int > > dist(n, {INF, 0});
    priority_queue < pair < ll, pair < int, int > > > pq;
    dist[s] = make_pair(0, 0);
    pq.push(make_pair(0, make_pair(s, 0)));
    
    while (!pq.empty()) {
        ll 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].first != d && l >= dist[u].second) continue;
        for (pair < int, int > vecino : adj[u]) {
            int v = vecino.first;
            int w = vecino.second;
            if (dist[v].first > d + w) {
                dist[v] = make_pair(d + w, l + 1);
                pq.push(make_pair(-dist[v].first, make_pair(v, l + 1)));
            }
        }
    }
    if (dist[f].first == INF) return -1;
    return dist[f].first;
}
 
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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 340 KB Output is correct
2 Correct 13 ms 340 KB Output is correct
3 Incorrect 39 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 53 ms 340 KB Output is correct
8 Correct 55 ms 344 KB Output is correct
9 Incorrect 82 ms 352 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 13 ms 340 KB Output is correct
9 Incorrect 39 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -