Submission #705880

# Submission time Handle Problem Language Result Execution time Memory
705880 2023-03-05T14:57:21 Z Gital Autobus (COCI22_autobus) C++11
0 / 70
3 ms 3156 KB
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

ll n,m,a,b,w;
ll k,q,c,d;
ll adj[72][72];
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
ll dp[72][72][72];
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        cin >> a >> b >> w;
        adj[a][b] = w;
    }
    cin >> k >> q;
    if(k > 70) k = 70;
    for(int i = 0; i < 71; i++) {
        for(int j = 0; j < 71; j++) {
            for(int l= 0; l < 71; l++) dp[i][j][l] = -1;
        }
    }
    for(int j = 1; j <= n; j++) {
        pq.push({0,j});
        for(int i = 0; i < 72; i++) dp[j][j][i] = 0;
        while(!pq.empty()) {
            a = pq.top().first;
            b = pq.top().second;
            pq.pop();
            for(int i = 1; i <= 70; i++) {
                bool able = false;
                if(adj[b][i] == 0) continue;
                for(int l = 0; l < k; l++) {
                    if(dp[j][b][l] != -1  && (dp[j][i][l + 1] == -1 || dp[j][i][l + 1] > dp[j][b][l] + adj[b][i])) {
                        dp[j][i][l + 1] = dp[j][b][l] + adj[b][i];
                        if(!able) pq.push({dp[j][i][l + 1],i});
                        able = true;
                    }
                }

            }
        }
    }
    /*for(int i = 1; i < 5; i++) {
        cout << "i = " << i << endl;
        for(int j = 1; j < 5; j++) {
            cout << "j = " << j << endl;
            for(int l= 0; l < 2; l++)  {
                cout << dp[i][j][l] << ' ';
            }
            cout << endl;
        }
    }*/
    for(int i = 0; i < q; i++) {
        cin >> c >> d;
        cout << dp[c][d][k] << endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -