Submission #705875

# Submission time Handle Problem Language Result Execution time Memory
705875 2023-03-05T14:47:06 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;
vector<pair<ll,ll>> v[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;
        v[a].push_back({w,b});
    }
    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 = 0; i < v[b].size(); i++) {
                bool able = false;
                for(int l = 0; l < k; l++) {
                    if(dp[j][b][l] == -1) break;
                    if(dp[j][b][l] != -1  && (dp[j][v[b][i].second][l + 1] == -1 || dp[j][v[b][i].second][l + 1] > dp[j][b][l] + v[b][i].first)) {
                        dp[j][v[b][i].second][l + 1] = dp[j][b][l] + v[b][i].first;
                        if(!able) pq.push({dp[j][v[b][i].second][l + 1],v[b][i].second});
                        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;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:32:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             for(int i = 0; i < v[b].size(); i++) {
      |                            ~~^~~~~~~~~~~~~
# 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 Correct 3 ms 3156 KB Output is correct
2 Incorrect 3 ms 3156 KB Output isn't correct
3 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 -