답안 #882781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882781 2023-12-03T17:46:40 Z Youssif_Elkadi Autobus (COCI22_autobus) C++17
70 / 70
116 ms 8444 KB
#include <bits/stdc++.h>
using namespace std;
const long long N = 70 + 5, inf = 1e17 + 5, mod = 1e9 + 7;
int dis[N][N][N];
int edges[N][N];
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    memset(edges, '?', sizeof edges);
    memset(dis, '?', sizeof dis);
    for (int i = 1; i <= n; i++)
        dis[i][i][0] = 0, edges[i][i] = 0;
    for (int i = 0; i < m; i++)
    {
        int u, v, c;
        cin >> u >> v >> c;
        edges[u][v] = min(edges[u][v], c);
    }
    int k, q;
    cin >> k >> q;
    k = min(k, n - 1);
    for (int i = 1; i <= n; i++)
    {
        for (int kk = 1; kk <= k; kk++)
        {
            for (int j = 1; j <= n; j++)
                dis[i][j][kk] = dis[i][j][kk - 1];
            for (int u = 1; u <= n; u++)
                for (int v = 1; v <= n; v++)
                    if (dis[i][v][kk] > dis[i][u][kk - 1] + edges[u][v])
                        dis[i][v][kk] = dis[i][u][kk - 1] + edges[u][v];
        }
    }
    while (q--)
    {
        int x, y;
        cin >> x >> y;
        if (dis[x][y][k] > (int)1e9)
            cout << -1 << "\n";
        else
            cout << dis[x][y][k] << "\n";
    }
}
/*
10
-1
0
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1880 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2140 KB Output is correct
2 Correct 4 ms 2140 KB Output is correct
3 Correct 3 ms 2140 KB Output is correct
4 Correct 3 ms 2140 KB Output is correct
5 Correct 3 ms 2140 KB Output is correct
6 Correct 3 ms 2140 KB Output is correct
7 Correct 4 ms 2136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1880 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 11 ms 2136 KB Output is correct
8 Correct 33 ms 2136 KB Output is correct
9 Correct 4 ms 2136 KB Output is correct
10 Correct 15 ms 2140 KB Output is correct
11 Correct 7 ms 2140 KB Output is correct
12 Correct 29 ms 2200 KB Output is correct
13 Correct 73 ms 8016 KB Output is correct
14 Correct 73 ms 8112 KB Output is correct
15 Correct 94 ms 8372 KB Output is correct
16 Correct 80 ms 8244 KB Output is correct
17 Correct 87 ms 8256 KB Output is correct
18 Correct 72 ms 8112 KB Output is correct
19 Correct 97 ms 8104 KB Output is correct
20 Correct 87 ms 8112 KB Output is correct
21 Correct 77 ms 8404 KB Output is correct
22 Correct 77 ms 8236 KB Output is correct
23 Correct 75 ms 8272 KB Output is correct
24 Correct 85 ms 8272 KB Output is correct
25 Correct 75 ms 8444 KB Output is correct
26 Correct 79 ms 8276 KB Output is correct
27 Correct 92 ms 8372 KB Output is correct
28 Correct 80 ms 8236 KB Output is correct
29 Correct 77 ms 8124 KB Output is correct
30 Correct 77 ms 7984 KB Output is correct
31 Correct 101 ms 7976 KB Output is correct
32 Correct 96 ms 8020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1880 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 2 ms 2140 KB Output is correct
8 Correct 4 ms 2140 KB Output is correct
9 Correct 3 ms 2140 KB Output is correct
10 Correct 3 ms 2140 KB Output is correct
11 Correct 3 ms 2140 KB Output is correct
12 Correct 3 ms 2140 KB Output is correct
13 Correct 4 ms 2136 KB Output is correct
14 Correct 11 ms 2136 KB Output is correct
15 Correct 33 ms 2136 KB Output is correct
16 Correct 4 ms 2136 KB Output is correct
17 Correct 15 ms 2140 KB Output is correct
18 Correct 7 ms 2140 KB Output is correct
19 Correct 29 ms 2200 KB Output is correct
20 Correct 73 ms 8016 KB Output is correct
21 Correct 73 ms 8112 KB Output is correct
22 Correct 94 ms 8372 KB Output is correct
23 Correct 80 ms 8244 KB Output is correct
24 Correct 87 ms 8256 KB Output is correct
25 Correct 72 ms 8112 KB Output is correct
26 Correct 97 ms 8104 KB Output is correct
27 Correct 87 ms 8112 KB Output is correct
28 Correct 77 ms 8404 KB Output is correct
29 Correct 77 ms 8236 KB Output is correct
30 Correct 75 ms 8272 KB Output is correct
31 Correct 85 ms 8272 KB Output is correct
32 Correct 75 ms 8444 KB Output is correct
33 Correct 79 ms 8276 KB Output is correct
34 Correct 92 ms 8372 KB Output is correct
35 Correct 80 ms 8236 KB Output is correct
36 Correct 77 ms 8124 KB Output is correct
37 Correct 77 ms 7984 KB Output is correct
38 Correct 101 ms 7976 KB Output is correct
39 Correct 96 ms 8020 KB Output is correct
40 Correct 8 ms 2140 KB Output is correct
41 Correct 27 ms 2144 KB Output is correct
42 Correct 8 ms 2396 KB Output is correct
43 Correct 27 ms 2140 KB Output is correct
44 Correct 6 ms 2140 KB Output is correct
45 Correct 28 ms 2212 KB Output is correct
46 Correct 74 ms 8104 KB Output is correct
47 Correct 86 ms 8232 KB Output is correct
48 Correct 86 ms 8108 KB Output is correct
49 Correct 108 ms 8276 KB Output is correct
50 Correct 73 ms 8236 KB Output is correct
51 Correct 78 ms 8272 KB Output is correct
52 Correct 77 ms 8108 KB Output is correct
53 Correct 97 ms 8272 KB Output is correct
54 Correct 74 ms 8368 KB Output is correct
55 Correct 74 ms 8364 KB Output is correct
56 Correct 108 ms 8364 KB Output is correct
57 Correct 97 ms 8272 KB Output is correct
58 Correct 85 ms 8364 KB Output is correct
59 Correct 84 ms 8272 KB Output is correct
60 Correct 116 ms 8360 KB Output is correct
61 Correct 99 ms 8272 KB Output is correct
62 Correct 72 ms 8108 KB Output is correct
63 Correct 79 ms 8108 KB Output is correct
64 Correct 80 ms 8024 KB Output is correct
65 Correct 113 ms 7980 KB Output is correct