Submission #1006867

# Submission time Handle Problem Language Result Execution time Memory
1006867 2024-06-24T09:25:17 Z overwatch9 Toll (BOI17_toll) C++17
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 50;
vector <pair <int, int>> adj[maxn];
ll dis[maxn];
bool processed[maxn];
queue <int> modified;
ll dijkstra(int st, int ed) {
    dis[st] = 0;
    priority_queue <pair <ll, int>> pq;
    modified.push(st);
    pq.push({0, st});
    while (!pq.empty()) {
        int s = pq.top().second;
        pq.pop();
        if (processed[s])
            continue;
        processed[s] = true;
        for (auto i : adj[s]) {
            if (dis[i.first] > dis[s] + i.second) {
                if (dis[i.first] == 1e18)
                    modified.push(i.first);
                dis[i.first] = dis[s] + i.second;
                pq.push({-dis[i.first], i.first});
            }
        }
    }
    int ans = 0;
    if (ed != -1) {
        if (dis[ed] == 1e18)
            dis[ed] = -1;
        ans = dis[ed];
        while (!modified.empty()) {
            dis[modified.front()] = 1e18;
            processed[modified.front()] = false;
            modified.pop();
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int K, N, M, O;
    cin >> K >> N >> M >> O;
    for (int i = 0; i < M; i++) {
        int a, b, t;
        cin >> a >> b >> t;
        adj[a].push_back({b, t});
    }
    fill(dis, dis + N + 1, 1e18);
    vector <pair <int, int>> queries(O);
    bool all0 = true;
    for (int i = 0; i < O; i++) {
        cin >> queries[i].first >> queries[i].second;
        if (queries[i].first != 0)
            all0 = false;
    }
    if (all0)
        dijkstra(0, -1);
    for (int i = 0; i < O; i++) {
        if (all0) {
            if (dis[queries[i].second] == 1e18)
                cout << -1 << '\n';
            else
                cout << dis[queries[i].second] << '\n';
        } else {
            cout << dijkstra(queries[i].first, queries[i].second) << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -