답안 #883859

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883859 2023-12-06T08:15:02 Z borisAngelov Autobus (COCI22_autobus) C++17
70 / 70
117 ms 9904 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 75;
const long long inf = (1LL << 60);

int n, m;
int k, q;

long long dist[maxn][maxn][maxn];
long long mat[maxn][maxn];

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n >> m;

    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            mat[i][j] = inf;

            for (int k = 0; k <= n; ++k)
            {
                dist[i][j][k] = inf;
            }
        }

        dist[i][i][0] = 0;
    }

    for (int i = 1; i <= m; ++i)
    {
        int x, y, w;
        cin >> x >> y >> w;

        if (mat[x][y] > w)
        {
            mat[x][y] = w;
        }
    }

    cin >> k >> q;

    if (k > n)
    {
        k = n;
    }

    for (int i = 1; i <= k; ++i)
    {
        for (int x = 1; x <= n; ++x)
        {
            for (int y = 1; y <= n; ++y)
            {
                for (int z = 1; z <= n; ++z)
                {
                    dist[x][y][i] = min(dist[x][y][i], dist[x][z][i - 1] + mat[z][y]);
                }
            }
        }
    }

    for (int i = 1; i <= q; ++i)
    {
        int x, y;
        cin >> x >> y;

        long long ans = inf;

        for (int j = 0; j <= k; ++j)
        {
            ans = min(ans, dist[x][y][j]);
        }

        if (ans == inf)
        {
            cout << -1 << "\n";
        }
        else
        {
            cout << ans << "\n";
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3624 KB Output is correct
2 Correct 3 ms 3420 KB Output is correct
3 Correct 3 ms 3420 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 3 ms 3420 KB Output is correct
6 Correct 3 ms 3676 KB Output is correct
7 Correct 3 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2512 KB Output is correct
7 Correct 10 ms 3420 KB Output is correct
8 Correct 26 ms 3572 KB Output is correct
9 Correct 3 ms 3416 KB Output is correct
10 Correct 15 ms 3420 KB Output is correct
11 Correct 7 ms 3672 KB Output is correct
12 Correct 19 ms 3420 KB Output is correct
13 Correct 72 ms 9556 KB Output is correct
14 Correct 73 ms 9568 KB Output is correct
15 Correct 104 ms 9572 KB Output is correct
16 Correct 79 ms 9712 KB Output is correct
17 Correct 78 ms 9704 KB Output is correct
18 Correct 88 ms 9568 KB Output is correct
19 Correct 96 ms 9572 KB Output is correct
20 Correct 84 ms 9788 KB Output is correct
21 Correct 73 ms 9820 KB Output is correct
22 Correct 92 ms 9812 KB Output is correct
23 Correct 76 ms 9708 KB Output is correct
24 Correct 98 ms 9836 KB Output is correct
25 Correct 82 ms 9904 KB Output is correct
26 Correct 79 ms 9808 KB Output is correct
27 Correct 81 ms 9704 KB Output is correct
28 Correct 79 ms 9808 KB Output is correct
29 Correct 74 ms 9556 KB Output is correct
30 Correct 84 ms 9644 KB Output is correct
31 Correct 85 ms 9556 KB Output is correct
32 Correct 97 ms 9556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2512 KB Output is correct
7 Correct 2 ms 3624 KB Output is correct
8 Correct 3 ms 3420 KB Output is correct
9 Correct 3 ms 3420 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 3 ms 3420 KB Output is correct
12 Correct 3 ms 3676 KB Output is correct
13 Correct 3 ms 3676 KB Output is correct
14 Correct 10 ms 3420 KB Output is correct
15 Correct 26 ms 3572 KB Output is correct
16 Correct 3 ms 3416 KB Output is correct
17 Correct 15 ms 3420 KB Output is correct
18 Correct 7 ms 3672 KB Output is correct
19 Correct 19 ms 3420 KB Output is correct
20 Correct 72 ms 9556 KB Output is correct
21 Correct 73 ms 9568 KB Output is correct
22 Correct 104 ms 9572 KB Output is correct
23 Correct 79 ms 9712 KB Output is correct
24 Correct 78 ms 9704 KB Output is correct
25 Correct 88 ms 9568 KB Output is correct
26 Correct 96 ms 9572 KB Output is correct
27 Correct 84 ms 9788 KB Output is correct
28 Correct 73 ms 9820 KB Output is correct
29 Correct 92 ms 9812 KB Output is correct
30 Correct 76 ms 9708 KB Output is correct
31 Correct 98 ms 9836 KB Output is correct
32 Correct 82 ms 9904 KB Output is correct
33 Correct 79 ms 9808 KB Output is correct
34 Correct 81 ms 9704 KB Output is correct
35 Correct 79 ms 9808 KB Output is correct
36 Correct 74 ms 9556 KB Output is correct
37 Correct 84 ms 9644 KB Output is correct
38 Correct 85 ms 9556 KB Output is correct
39 Correct 97 ms 9556 KB Output is correct
40 Correct 8 ms 3420 KB Output is correct
41 Correct 26 ms 3420 KB Output is correct
42 Correct 4 ms 3420 KB Output is correct
43 Correct 26 ms 3420 KB Output is correct
44 Correct 6 ms 3420 KB Output is correct
45 Correct 26 ms 3420 KB Output is correct
46 Correct 77 ms 9564 KB Output is correct
47 Correct 83 ms 9692 KB Output is correct
48 Correct 87 ms 9556 KB Output is correct
49 Correct 104 ms 9812 KB Output is correct
50 Correct 73 ms 9556 KB Output is correct
51 Correct 77 ms 9556 KB Output is correct
52 Correct 73 ms 9556 KB Output is correct
53 Correct 102 ms 9776 KB Output is correct
54 Correct 76 ms 9812 KB Output is correct
55 Correct 73 ms 9808 KB Output is correct
56 Correct 94 ms 9812 KB Output is correct
57 Correct 95 ms 9808 KB Output is correct
58 Correct 74 ms 9812 KB Output is correct
59 Correct 84 ms 9812 KB Output is correct
60 Correct 117 ms 9708 KB Output is correct
61 Correct 97 ms 9840 KB Output is correct
62 Correct 72 ms 9572 KB Output is correct
63 Correct 78 ms 9576 KB Output is correct
64 Correct 79 ms 9556 KB Output is correct
65 Correct 96 ms 9436 KB Output is correct