Submission #705882

# Submission time Handle Problem Language Result Execution time Memory
705882 2023-03-05T15:05:53 Z Gital Autobus (COCI22_autobus) C++11
70 / 70
349 ms 9576 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;
        if(adj[a][b] == 0 || adj[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 <= n; 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 Correct 2 ms 3156 KB Output is correct
2 Correct 1 ms 3156 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Correct 1 ms 3156 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3156 KB Output is correct
2 Correct 3 ms 3284 KB Output is correct
3 Correct 5 ms 3284 KB Output is correct
4 Correct 7 ms 3156 KB Output is correct
5 Correct 10 ms 3256 KB Output is correct
6 Correct 13 ms 3156 KB Output is correct
7 Correct 17 ms 3256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 1 ms 3156 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Correct 1 ms 3156 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
7 Correct 10 ms 3256 KB Output is correct
8 Correct 13 ms 3284 KB Output is correct
9 Correct 8 ms 3156 KB Output is correct
10 Correct 21 ms 3156 KB Output is correct
11 Correct 27 ms 3156 KB Output is correct
12 Correct 93 ms 3240 KB Output is correct
13 Correct 98 ms 3164 KB Output is correct
14 Correct 132 ms 9308 KB Output is correct
15 Correct 223 ms 9304 KB Output is correct
16 Correct 144 ms 9288 KB Output is correct
17 Correct 99 ms 9416 KB Output is correct
18 Correct 100 ms 9416 KB Output is correct
19 Correct 207 ms 9452 KB Output is correct
20 Correct 149 ms 9444 KB Output is correct
21 Correct 101 ms 9420 KB Output is correct
22 Correct 107 ms 9404 KB Output is correct
23 Correct 106 ms 9432 KB Output is correct
24 Correct 140 ms 9416 KB Output is correct
25 Correct 111 ms 9564 KB Output is correct
26 Correct 135 ms 9576 KB Output is correct
27 Correct 132 ms 9572 KB Output is correct
28 Correct 131 ms 9548 KB Output is correct
29 Correct 113 ms 9308 KB Output is correct
30 Correct 155 ms 9324 KB Output is correct
31 Correct 242 ms 9320 KB Output is correct
32 Correct 348 ms 9316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 1 ms 3156 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Correct 1 ms 3156 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
7 Correct 3 ms 3156 KB Output is correct
8 Correct 3 ms 3284 KB Output is correct
9 Correct 5 ms 3284 KB Output is correct
10 Correct 7 ms 3156 KB Output is correct
11 Correct 10 ms 3256 KB Output is correct
12 Correct 13 ms 3156 KB Output is correct
13 Correct 17 ms 3256 KB Output is correct
14 Correct 10 ms 3256 KB Output is correct
15 Correct 13 ms 3284 KB Output is correct
16 Correct 8 ms 3156 KB Output is correct
17 Correct 21 ms 3156 KB Output is correct
18 Correct 27 ms 3156 KB Output is correct
19 Correct 93 ms 3240 KB Output is correct
20 Correct 98 ms 3164 KB Output is correct
21 Correct 132 ms 9308 KB Output is correct
22 Correct 223 ms 9304 KB Output is correct
23 Correct 144 ms 9288 KB Output is correct
24 Correct 99 ms 9416 KB Output is correct
25 Correct 100 ms 9416 KB Output is correct
26 Correct 207 ms 9452 KB Output is correct
27 Correct 149 ms 9444 KB Output is correct
28 Correct 101 ms 9420 KB Output is correct
29 Correct 107 ms 9404 KB Output is correct
30 Correct 106 ms 9432 KB Output is correct
31 Correct 140 ms 9416 KB Output is correct
32 Correct 111 ms 9564 KB Output is correct
33 Correct 135 ms 9576 KB Output is correct
34 Correct 132 ms 9572 KB Output is correct
35 Correct 131 ms 9548 KB Output is correct
36 Correct 113 ms 9308 KB Output is correct
37 Correct 155 ms 9324 KB Output is correct
38 Correct 242 ms 9320 KB Output is correct
39 Correct 348 ms 9316 KB Output is correct
40 Correct 9 ms 3284 KB Output is correct
41 Correct 15 ms 3284 KB Output is correct
42 Correct 11 ms 3300 KB Output is correct
43 Correct 31 ms 3288 KB Output is correct
44 Correct 31 ms 3268 KB Output is correct
45 Correct 168 ms 3336 KB Output is correct
46 Correct 103 ms 9380 KB Output is correct
47 Correct 179 ms 9292 KB Output is correct
48 Correct 120 ms 9300 KB Output is correct
49 Correct 254 ms 9420 KB Output is correct
50 Correct 105 ms 9420 KB Output is correct
51 Correct 121 ms 9448 KB Output is correct
52 Correct 91 ms 9416 KB Output is correct
53 Correct 203 ms 9564 KB Output is correct
54 Correct 97 ms 9428 KB Output is correct
55 Correct 96 ms 9400 KB Output is correct
56 Correct 176 ms 9428 KB Output is correct
57 Correct 204 ms 9420 KB Output is correct
58 Correct 95 ms 9560 KB Output is correct
59 Correct 150 ms 9556 KB Output is correct
60 Correct 212 ms 9548 KB Output is correct
61 Correct 218 ms 9548 KB Output is correct
62 Correct 94 ms 9292 KB Output is correct
63 Correct 152 ms 9316 KB Output is correct
64 Correct 185 ms 9324 KB Output is correct
65 Correct 349 ms 9320 KB Output is correct