Submission #897240

# Submission time Handle Problem Language Result Execution time Memory
897240 2024-01-02T19:21:36 Z SalihSahin Autobus (COCI22_autobus) C++14
70 / 70
295 ms 9812 KB
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
 
const int mod = 1e9 + 7;
const int inf = 1e17*2;
const int N = 3e5 + 5;
 
int32_t main(){
    int n, m;
    cin>>n>>m;
    int edge[n][n], dis[n][n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            edge[i][j] = inf;
            for(int l = 0; l < n; l++){
                dis[i][j][l] = inf;
            }
        }
    }

    for(int i = 0; i < m; i++){
        int u, v, w;
        cin>>u>>v>>w;
        edge[u-1][v-1] = min(edge[u-1][v-1], w);
    }

    int k, q;
    cin>>k>>q;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            dis[i][j][1] = edge[i][j];
        }
        dis[i][i][1] = 0;
    }

    for(int asama = 2; asama < n; asama++){
        for(int l = 0; l < n; l++){
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    dis[i][j][asama] = min(dis[i][j][asama], dis[i][l][asama-1] + dis[l][j][1]);
                }
            }
        }
    }

    while(q--){
        int c, d;
        cin>>c>>d;
        c--, d--;

        if(dis[c][d][min(k, n-1)] == inf) cout<<-1<<endl;
        else cout<<dis[c][d][min(k, n-1)]<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 3156 KB Output is correct
2 Correct 44 ms 3156 KB Output is correct
3 Correct 45 ms 3156 KB Output is correct
4 Correct 48 ms 3164 KB Output is correct
5 Correct 45 ms 3164 KB Output is correct
6 Correct 46 ms 3220 KB Output is correct
7 Correct 47 ms 3204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 45 ms 3160 KB Output is correct
8 Correct 45 ms 3180 KB Output is correct
9 Correct 44 ms 3160 KB Output is correct
10 Correct 44 ms 3180 KB Output is correct
11 Correct 46 ms 3164 KB Output is correct
12 Correct 46 ms 3160 KB Output is correct
13 Correct 290 ms 9252 KB Output is correct
14 Correct 267 ms 9140 KB Output is correct
15 Correct 277 ms 9300 KB Output is correct
16 Correct 265 ms 9044 KB Output is correct
17 Correct 275 ms 9296 KB Output is correct
18 Correct 273 ms 9300 KB Output is correct
19 Correct 268 ms 9136 KB Output is correct
20 Correct 274 ms 9384 KB Output is correct
21 Correct 270 ms 9296 KB Output is correct
22 Correct 269 ms 9524 KB Output is correct
23 Correct 283 ms 9292 KB Output is correct
24 Correct 272 ms 9296 KB Output is correct
25 Correct 285 ms 9776 KB Output is correct
26 Correct 273 ms 9588 KB Output is correct
27 Correct 285 ms 9812 KB Output is correct
28 Correct 274 ms 9392 KB Output is correct
29 Correct 272 ms 9048 KB Output is correct
30 Correct 271 ms 9128 KB Output is correct
31 Correct 262 ms 9016 KB Output is correct
32 Correct 268 ms 9256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 50 ms 3156 KB Output is correct
8 Correct 44 ms 3156 KB Output is correct
9 Correct 45 ms 3156 KB Output is correct
10 Correct 48 ms 3164 KB Output is correct
11 Correct 45 ms 3164 KB Output is correct
12 Correct 46 ms 3220 KB Output is correct
13 Correct 47 ms 3204 KB Output is correct
14 Correct 45 ms 3160 KB Output is correct
15 Correct 45 ms 3180 KB Output is correct
16 Correct 44 ms 3160 KB Output is correct
17 Correct 44 ms 3180 KB Output is correct
18 Correct 46 ms 3164 KB Output is correct
19 Correct 46 ms 3160 KB Output is correct
20 Correct 290 ms 9252 KB Output is correct
21 Correct 267 ms 9140 KB Output is correct
22 Correct 277 ms 9300 KB Output is correct
23 Correct 265 ms 9044 KB Output is correct
24 Correct 275 ms 9296 KB Output is correct
25 Correct 273 ms 9300 KB Output is correct
26 Correct 268 ms 9136 KB Output is correct
27 Correct 274 ms 9384 KB Output is correct
28 Correct 270 ms 9296 KB Output is correct
29 Correct 269 ms 9524 KB Output is correct
30 Correct 283 ms 9292 KB Output is correct
31 Correct 272 ms 9296 KB Output is correct
32 Correct 285 ms 9776 KB Output is correct
33 Correct 273 ms 9588 KB Output is correct
34 Correct 285 ms 9812 KB Output is correct
35 Correct 274 ms 9392 KB Output is correct
36 Correct 272 ms 9048 KB Output is correct
37 Correct 271 ms 9128 KB Output is correct
38 Correct 262 ms 9016 KB Output is correct
39 Correct 268 ms 9256 KB Output is correct
40 Correct 44 ms 3160 KB Output is correct
41 Correct 43 ms 3164 KB Output is correct
42 Correct 44 ms 3164 KB Output is correct
43 Correct 46 ms 3176 KB Output is correct
44 Correct 46 ms 3164 KB Output is correct
45 Correct 63 ms 3212 KB Output is correct
46 Correct 266 ms 9128 KB Output is correct
47 Correct 265 ms 9048 KB Output is correct
48 Correct 287 ms 9416 KB Output is correct
49 Correct 269 ms 9040 KB Output is correct
50 Correct 293 ms 9552 KB Output is correct
51 Correct 272 ms 9384 KB Output is correct
52 Correct 268 ms 9272 KB Output is correct
53 Correct 274 ms 9340 KB Output is correct
54 Correct 272 ms 9360 KB Output is correct
55 Correct 289 ms 9508 KB Output is correct
56 Correct 271 ms 9300 KB Output is correct
57 Correct 286 ms 9252 KB Output is correct
58 Correct 282 ms 9556 KB Output is correct
59 Correct 276 ms 9392 KB Output is correct
60 Correct 295 ms 9556 KB Output is correct
61 Correct 272 ms 9300 KB Output is correct
62 Correct 265 ms 9124 KB Output is correct
63 Correct 283 ms 9172 KB Output is correct
64 Correct 265 ms 9040 KB Output is correct
65 Correct 288 ms 9128 KB Output is correct