Submission #701672

# Submission time Handle Problem Language Result Execution time Memory
701672 2023-02-21T22:28:24 Z delrey Autobus (COCI22_autobus) C++14
70 / 70
384 ms 8116 KB
#include <iostream>

using namespace std;

const int inf = 1000000000;
int n, m;
int adj[70][70];
int k, q;
int dp[70][70][70]; //[distance][town A][town B]

int main()
{
    cin>>n>>m;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
        {
            adj[i][j] = inf;
            for(int d = 0; d < n; d++)
                dp[d][i][j] = inf;
        }
    for(int i = 0; i < n; i++)
    {
        adj[i][i] = 0;
        dp[0][i][i] = 0;
    }
    for(int i = 0; i < m; i++)
    {
        int a, b, t;
        cin>>a>>b>>t;
        a--;
        b--;
        adj[a][b] = min(adj[a][b], t);
    }
    cin>>k>>q;
    if(k > n - 1)
        k = n - 1;
    for(int d = 1; d <= k; d++)
        for(int a = 0; a < n; a++)
            for(int b = 0; b < n; b++)
                for(int x = 0; x < n; x++)
                    if(dp[d - 1][a][x] != inf && adj[x][b] != inf)
                        dp[d][a][b] = min(dp[d][a][b], dp[d - 1][a][x] + adj[x][b]);
    while(q--)
    {
        int from, to;
        cin>>from>>to;
        from--;
        to--;
        if(dp[k][from][to] == inf)
            cout<<-1<<endl;
        else
            cout<<dp[k][from][to]<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1620 KB Output is correct
2 Correct 10 ms 1620 KB Output is correct
3 Correct 11 ms 1620 KB Output is correct
4 Correct 11 ms 1620 KB Output is correct
5 Correct 11 ms 1676 KB Output is correct
6 Correct 13 ms 1672 KB Output is correct
7 Correct 14 ms 1660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 24 ms 1672 KB Output is correct
8 Correct 57 ms 1768 KB Output is correct
9 Correct 12 ms 1660 KB Output is correct
10 Correct 42 ms 1636 KB Output is correct
11 Correct 20 ms 1620 KB Output is correct
12 Correct 52 ms 1732 KB Output is correct
13 Correct 290 ms 7788 KB Output is correct
14 Correct 296 ms 7768 KB Output is correct
15 Correct 340 ms 7772 KB Output is correct
16 Correct 322 ms 7780 KB Output is correct
17 Correct 300 ms 7832 KB Output is correct
18 Correct 301 ms 7768 KB Output is correct
19 Correct 355 ms 7780 KB Output is correct
20 Correct 328 ms 7768 KB Output is correct
21 Correct 300 ms 7900 KB Output is correct
22 Correct 314 ms 7904 KB Output is correct
23 Correct 318 ms 7912 KB Output is correct
24 Correct 331 ms 7904 KB Output is correct
25 Correct 306 ms 8024 KB Output is correct
26 Correct 316 ms 7908 KB Output is correct
27 Correct 329 ms 8076 KB Output is correct
28 Correct 316 ms 7884 KB Output is correct
29 Correct 295 ms 7656 KB Output is correct
30 Correct 297 ms 7632 KB Output is correct
31 Correct 322 ms 7732 KB Output is correct
32 Correct 364 ms 7856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 9 ms 1620 KB Output is correct
8 Correct 10 ms 1620 KB Output is correct
9 Correct 11 ms 1620 KB Output is correct
10 Correct 11 ms 1620 KB Output is correct
11 Correct 11 ms 1676 KB Output is correct
12 Correct 13 ms 1672 KB Output is correct
13 Correct 14 ms 1660 KB Output is correct
14 Correct 24 ms 1672 KB Output is correct
15 Correct 57 ms 1768 KB Output is correct
16 Correct 12 ms 1660 KB Output is correct
17 Correct 42 ms 1636 KB Output is correct
18 Correct 20 ms 1620 KB Output is correct
19 Correct 52 ms 1732 KB Output is correct
20 Correct 290 ms 7788 KB Output is correct
21 Correct 296 ms 7768 KB Output is correct
22 Correct 340 ms 7772 KB Output is correct
23 Correct 322 ms 7780 KB Output is correct
24 Correct 300 ms 7832 KB Output is correct
25 Correct 301 ms 7768 KB Output is correct
26 Correct 355 ms 7780 KB Output is correct
27 Correct 328 ms 7768 KB Output is correct
28 Correct 300 ms 7900 KB Output is correct
29 Correct 314 ms 7904 KB Output is correct
30 Correct 318 ms 7912 KB Output is correct
31 Correct 331 ms 7904 KB Output is correct
32 Correct 306 ms 8024 KB Output is correct
33 Correct 316 ms 7908 KB Output is correct
34 Correct 329 ms 8076 KB Output is correct
35 Correct 316 ms 7884 KB Output is correct
36 Correct 295 ms 7656 KB Output is correct
37 Correct 297 ms 7632 KB Output is correct
38 Correct 322 ms 7732 KB Output is correct
39 Correct 364 ms 7856 KB Output is correct
40 Correct 21 ms 1692 KB Output is correct
41 Correct 53 ms 1672 KB Output is correct
42 Correct 15 ms 1620 KB Output is correct
43 Correct 67 ms 1676 KB Output is correct
44 Correct 23 ms 1748 KB Output is correct
45 Correct 75 ms 1720 KB Output is correct
46 Correct 292 ms 7776 KB Output is correct
47 Correct 326 ms 7900 KB Output is correct
48 Correct 332 ms 7780 KB Output is correct
49 Correct 363 ms 7756 KB Output is correct
50 Correct 337 ms 7780 KB Output is correct
51 Correct 307 ms 7780 KB Output is correct
52 Correct 297 ms 7784 KB Output is correct
53 Correct 359 ms 7768 KB Output is correct
54 Correct 305 ms 7908 KB Output is correct
55 Correct 302 ms 7884 KB Output is correct
56 Correct 359 ms 7896 KB Output is correct
57 Correct 360 ms 7896 KB Output is correct
58 Correct 299 ms 7908 KB Output is correct
59 Correct 329 ms 7908 KB Output is correct
60 Correct 352 ms 7988 KB Output is correct
61 Correct 384 ms 8116 KB Output is correct
62 Correct 293 ms 7628 KB Output is correct
63 Correct 316 ms 7732 KB Output is correct
64 Correct 317 ms 7736 KB Output is correct
65 Correct 364 ms 7756 KB Output is correct