답안 #696616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696616 2023-02-07T01:27:22 Z socpite Autobus (COCI22_autobus) C++17
70 / 70
126 ms 5116 KB
#include<bits/stdc++.h>
using namespace std;

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int maxn = 75;
const ll inf = 1e18+5;

int n, m, k, q;

ll d[75][75][75];

ll adj[75][75];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(i == j)adj[i][j] = 0;
            else adj[i][j] = inf;
        }
    }
    for(int i = 0; i < m; i++){
        int a, b, w;
        cin >> a >> b >> w;
        adj[a][b] = min<ll>(adj[a][b], w);
    }
    cin >> k >> q;
    k = min(k, n);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int l = 0; l <= k; l++){
                if(l == 0 && i == j)d[i][j][l] = 0;
                else d[i][j][l] = inf;
            }
        }
    }
    for(int l = 1; l <= k; l++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                for(int v = 1; v <= n; v++){
                    d[i][j][l] = min(d[i][j][l], d[i][v][l-1] + adj[v][j]);
                }
            }
        }
    }
    while(q--){
        int a, b;
        cin >> a >> b;
        if(d[a][b][k] >= inf)cout << "-1";
        else cout << d[a][b][k];
        cout << "\n";
    }
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3412 KB Output is correct
2 Correct 3 ms 3412 KB Output is correct
3 Correct 5 ms 3412 KB Output is correct
4 Correct 3 ms 3412 KB Output is correct
5 Correct 4 ms 3412 KB Output is correct
6 Correct 4 ms 3412 KB Output is correct
7 Correct 7 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 12 ms 3412 KB Output is correct
8 Correct 30 ms 3424 KB Output is correct
9 Correct 4 ms 3412 KB Output is correct
10 Correct 17 ms 3412 KB Output is correct
11 Correct 8 ms 3444 KB Output is correct
12 Correct 20 ms 3412 KB Output is correct
13 Correct 84 ms 3468 KB Output is correct
14 Correct 90 ms 3560 KB Output is correct
15 Correct 107 ms 3548 KB Output is correct
16 Correct 96 ms 5016 KB Output is correct
17 Correct 89 ms 4888 KB Output is correct
18 Correct 88 ms 5044 KB Output is correct
19 Correct 121 ms 4956 KB Output is correct
20 Correct 101 ms 4940 KB Output is correct
21 Correct 90 ms 4924 KB Output is correct
22 Correct 94 ms 4952 KB Output is correct
23 Correct 96 ms 4988 KB Output is correct
24 Correct 106 ms 4884 KB Output is correct
25 Correct 96 ms 4964 KB Output is correct
26 Correct 96 ms 4900 KB Output is correct
27 Correct 107 ms 4956 KB Output is correct
28 Correct 125 ms 4944 KB Output is correct
29 Correct 88 ms 4812 KB Output is correct
30 Correct 99 ms 4864 KB Output is correct
31 Correct 100 ms 4912 KB Output is correct
32 Correct 113 ms 4836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 3 ms 3412 KB Output is correct
8 Correct 3 ms 3412 KB Output is correct
9 Correct 5 ms 3412 KB Output is correct
10 Correct 3 ms 3412 KB Output is correct
11 Correct 4 ms 3412 KB Output is correct
12 Correct 4 ms 3412 KB Output is correct
13 Correct 7 ms 3412 KB Output is correct
14 Correct 12 ms 3412 KB Output is correct
15 Correct 30 ms 3424 KB Output is correct
16 Correct 4 ms 3412 KB Output is correct
17 Correct 17 ms 3412 KB Output is correct
18 Correct 8 ms 3444 KB Output is correct
19 Correct 20 ms 3412 KB Output is correct
20 Correct 84 ms 3468 KB Output is correct
21 Correct 90 ms 3560 KB Output is correct
22 Correct 107 ms 3548 KB Output is correct
23 Correct 96 ms 5016 KB Output is correct
24 Correct 89 ms 4888 KB Output is correct
25 Correct 88 ms 5044 KB Output is correct
26 Correct 121 ms 4956 KB Output is correct
27 Correct 101 ms 4940 KB Output is correct
28 Correct 90 ms 4924 KB Output is correct
29 Correct 94 ms 4952 KB Output is correct
30 Correct 96 ms 4988 KB Output is correct
31 Correct 106 ms 4884 KB Output is correct
32 Correct 96 ms 4964 KB Output is correct
33 Correct 96 ms 4900 KB Output is correct
34 Correct 107 ms 4956 KB Output is correct
35 Correct 125 ms 4944 KB Output is correct
36 Correct 88 ms 4812 KB Output is correct
37 Correct 99 ms 4864 KB Output is correct
38 Correct 100 ms 4912 KB Output is correct
39 Correct 113 ms 4836 KB Output is correct
40 Correct 9 ms 3412 KB Output is correct
41 Correct 29 ms 3460 KB Output is correct
42 Correct 6 ms 3412 KB Output is correct
43 Correct 32 ms 3476 KB Output is correct
44 Correct 7 ms 3540 KB Output is correct
45 Correct 31 ms 3504 KB Output is correct
46 Correct 91 ms 4964 KB Output is correct
47 Correct 114 ms 4944 KB Output is correct
48 Correct 95 ms 4988 KB Output is correct
49 Correct 113 ms 4856 KB Output is correct
50 Correct 91 ms 5068 KB Output is correct
51 Correct 99 ms 4992 KB Output is correct
52 Correct 93 ms 5116 KB Output is correct
53 Correct 110 ms 4852 KB Output is correct
54 Correct 91 ms 5028 KB Output is correct
55 Correct 92 ms 4444 KB Output is correct
56 Correct 110 ms 4440 KB Output is correct
57 Correct 117 ms 4452 KB Output is correct
58 Correct 96 ms 4440 KB Output is correct
59 Correct 100 ms 4460 KB Output is correct
60 Correct 115 ms 4584 KB Output is correct
61 Correct 126 ms 4452 KB Output is correct
62 Correct 92 ms 4368 KB Output is correct
63 Correct 90 ms 4420 KB Output is correct
64 Correct 105 ms 4132 KB Output is correct
65 Correct 110 ms 4272 KB Output is correct