답안 #1087890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087890 2024-09-13T11:11:32 Z whtth Autobus (COCI22_autobus) C++14
70 / 70
100 ms 9556 KB
#include<bits/stdc++.h>
using namespace std;
long long n, m, road[71][71], mi[71][71][71], inf=1e12;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("autobus.inp", "r", stdin);
    //freopen("autobus.out", "w", stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(i==j)road[i][j]=0;
            else {
                road[i][j]=inf;
            }
            mi[i][j][0]=road[i][j];
        }
    }
    for(int o=1;o<=m;o++){
        long long a, b, v;
        cin>>a>>b>>v;
        road[a][b]=min(road[a][b], v);
        mi[a][b][1]=road[a][b];
    }
    for(int k=1;k<n;k++){///toi da di dc n-1 thanh pho
        for(int i=1;i<=n;i++){///thanh pho di
            for(int j=1;j<=n;j++){///thanh pho den
                mi[i][j][k]=mi[i][j][k-1];
                for(int h=1;h<=n;h++)mi[i][j][k]=min(mi[i][j][k], mi[i][h][k-1]+road[h][j]);///i->j or i->h->j
            }
        }
    }
    long long k, q;
    cin>>k>>q;
    k=min(k, n-1);
    for(int i=1;i<=q;i++){
        long long a, b;
        cin>>a>>b;
        if(mi[a][b][k]<inf)cout<<mi[a][b][k]<<"\n";
        else cout<<"-1\n";
    }
    return 0;
}























# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3164 KB Output is correct
2 Correct 19 ms 3272 KB Output is correct
3 Correct 21 ms 3276 KB Output is correct
4 Correct 19 ms 3164 KB Output is correct
5 Correct 19 ms 3164 KB Output is correct
6 Correct 19 ms 3340 KB Output is correct
7 Correct 24 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 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 18 ms 3280 KB Output is correct
8 Correct 19 ms 3164 KB Output is correct
9 Correct 19 ms 3164 KB Output is correct
10 Correct 20 ms 3160 KB Output is correct
11 Correct 20 ms 3160 KB Output is correct
12 Correct 19 ms 3348 KB Output is correct
13 Correct 87 ms 9296 KB Output is correct
14 Correct 90 ms 9300 KB Output is correct
15 Correct 100 ms 9300 KB Output is correct
16 Correct 81 ms 9380 KB Output is correct
17 Correct 91 ms 9300 KB Output is correct
18 Correct 84 ms 9296 KB Output is correct
19 Correct 80 ms 9296 KB Output is correct
20 Correct 91 ms 9284 KB Output is correct
21 Correct 87 ms 9300 KB Output is correct
22 Correct 86 ms 9508 KB Output is correct
23 Correct 85 ms 9296 KB Output is correct
24 Correct 86 ms 9300 KB Output is correct
25 Correct 82 ms 9556 KB Output is correct
26 Correct 84 ms 9552 KB Output is correct
27 Correct 90 ms 9552 KB Output is correct
28 Correct 93 ms 9372 KB Output is correct
29 Correct 84 ms 9296 KB Output is correct
30 Correct 90 ms 9252 KB Output is correct
31 Correct 84 ms 9300 KB Output is correct
32 Correct 79 ms 9296 KB Output is correct
# 결과 실행 시간 메모리 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 18 ms 3164 KB Output is correct
8 Correct 19 ms 3272 KB Output is correct
9 Correct 21 ms 3276 KB Output is correct
10 Correct 19 ms 3164 KB Output is correct
11 Correct 19 ms 3164 KB Output is correct
12 Correct 19 ms 3340 KB Output is correct
13 Correct 24 ms 3164 KB Output is correct
14 Correct 18 ms 3280 KB Output is correct
15 Correct 19 ms 3164 KB Output is correct
16 Correct 19 ms 3164 KB Output is correct
17 Correct 20 ms 3160 KB Output is correct
18 Correct 20 ms 3160 KB Output is correct
19 Correct 19 ms 3348 KB Output is correct
20 Correct 87 ms 9296 KB Output is correct
21 Correct 90 ms 9300 KB Output is correct
22 Correct 100 ms 9300 KB Output is correct
23 Correct 81 ms 9380 KB Output is correct
24 Correct 91 ms 9300 KB Output is correct
25 Correct 84 ms 9296 KB Output is correct
26 Correct 80 ms 9296 KB Output is correct
27 Correct 91 ms 9284 KB Output is correct
28 Correct 87 ms 9300 KB Output is correct
29 Correct 86 ms 9508 KB Output is correct
30 Correct 85 ms 9296 KB Output is correct
31 Correct 86 ms 9300 KB Output is correct
32 Correct 82 ms 9556 KB Output is correct
33 Correct 84 ms 9552 KB Output is correct
34 Correct 90 ms 9552 KB Output is correct
35 Correct 93 ms 9372 KB Output is correct
36 Correct 84 ms 9296 KB Output is correct
37 Correct 90 ms 9252 KB Output is correct
38 Correct 84 ms 9300 KB Output is correct
39 Correct 79 ms 9296 KB Output is correct
40 Correct 19 ms 3160 KB Output is correct
41 Correct 18 ms 3280 KB Output is correct
42 Correct 20 ms 3164 KB Output is correct
43 Correct 19 ms 3164 KB Output is correct
44 Correct 19 ms 3164 KB Output is correct
45 Correct 19 ms 3336 KB Output is correct
46 Correct 84 ms 9300 KB Output is correct
47 Correct 81 ms 9296 KB Output is correct
48 Correct 83 ms 9296 KB Output is correct
49 Correct 83 ms 9296 KB Output is correct
50 Correct 83 ms 9392 KB Output is correct
51 Correct 82 ms 9296 KB Output is correct
52 Correct 86 ms 9380 KB Output is correct
53 Correct 87 ms 9300 KB Output is correct
54 Correct 88 ms 9296 KB Output is correct
55 Correct 88 ms 9520 KB Output is correct
56 Correct 83 ms 9396 KB Output is correct
57 Correct 85 ms 9300 KB Output is correct
58 Correct 86 ms 9556 KB Output is correct
59 Correct 88 ms 9508 KB Output is correct
60 Correct 86 ms 9552 KB Output is correct
61 Correct 83 ms 9552 KB Output is correct
62 Correct 81 ms 9332 KB Output is correct
63 Correct 83 ms 9120 KB Output is correct
64 Correct 80 ms 9296 KB Output is correct
65 Correct 83 ms 9300 KB Output is correct