답안 #823722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
823722 2023-08-13T03:05:11 Z Sandarach151 Autobus (COCI22_autobus) C++17
70 / 70
139 ms 8012 KB
#include<iostream>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
 
const int MAXN=72, INF=1000000010;
int n, m, k, q, adj[MAXN][MAXN], dis[MAXN][MAXN][MAXN];
 
int main(){
    scanf("%d %d", &n, &m);
    forn(i, n) forn(j, n) adj[i][j]=INF;
    forn(i, n) adj[i][i]=0;
    forn(i, m){
        int a, b, t; scanf("%d %d %d", &a, &b, &t); --a, --b;
        adj[a][b]=min(adj[a][b], t);
    }
    scanf("%d %d", &k, &q);
    k = min(k, n-1);
    forn(it, k+1) forn(i, n) forn(j, n) dis[it][i][j]=INF;
    forn(it, k+1) forn(i, n) dis[it][i][i]=0;
    forn(it, k){
        forn(v, n) forn(i, n) forn(j, n){
            dis[it+1][v][j]=min(dis[it+1][v][j], dis[it][v][i] + adj[i][j]);
        }
    }
    forn(i, q){
        int a, b; scanf("%d %d", &a, &b), --a, --b;
        int d = dis[k][a][b];
        printf("%d\n", d==INF? -1 : d);
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         int a, b, t; scanf("%d %d %d", &a, &b, &t); --a, --b;
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d %d", &k, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:26:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         int a, b; scanf("%d %d", &a, &b), --a, --b;
      |                   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 10 ms 864 KB Output is correct
8 Correct 20 ms 1736 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 11 ms 1108 KB Output is correct
11 Correct 5 ms 596 KB Output is correct
12 Correct 14 ms 1344 KB Output is correct
13 Correct 91 ms 6552 KB Output is correct
14 Correct 90 ms 6572 KB Output is correct
15 Correct 103 ms 7632 KB Output is correct
16 Correct 103 ms 6828 KB Output is correct
17 Correct 91 ms 6564 KB Output is correct
18 Correct 90 ms 6576 KB Output is correct
19 Correct 116 ms 7952 KB Output is correct
20 Correct 106 ms 7220 KB Output is correct
21 Correct 91 ms 6696 KB Output is correct
22 Correct 91 ms 6828 KB Output is correct
23 Correct 110 ms 6832 KB Output is correct
24 Correct 102 ms 7340 KB Output is correct
25 Correct 91 ms 6700 KB Output is correct
26 Correct 126 ms 7088 KB Output is correct
27 Correct 115 ms 7144 KB Output is correct
28 Correct 114 ms 7040 KB Output is correct
29 Correct 104 ms 6452 KB Output is correct
30 Correct 117 ms 6704 KB Output is correct
31 Correct 112 ms 7088 KB Output is correct
32 Correct 105 ms 7728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 10 ms 864 KB Output is correct
15 Correct 20 ms 1736 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 11 ms 1108 KB Output is correct
18 Correct 5 ms 596 KB Output is correct
19 Correct 14 ms 1344 KB Output is correct
20 Correct 91 ms 6552 KB Output is correct
21 Correct 90 ms 6572 KB Output is correct
22 Correct 103 ms 7632 KB Output is correct
23 Correct 103 ms 6828 KB Output is correct
24 Correct 91 ms 6564 KB Output is correct
25 Correct 90 ms 6576 KB Output is correct
26 Correct 116 ms 7952 KB Output is correct
27 Correct 106 ms 7220 KB Output is correct
28 Correct 91 ms 6696 KB Output is correct
29 Correct 91 ms 6828 KB Output is correct
30 Correct 110 ms 6832 KB Output is correct
31 Correct 102 ms 7340 KB Output is correct
32 Correct 91 ms 6700 KB Output is correct
33 Correct 126 ms 7088 KB Output is correct
34 Correct 115 ms 7144 KB Output is correct
35 Correct 114 ms 7040 KB Output is correct
36 Correct 104 ms 6452 KB Output is correct
37 Correct 117 ms 6704 KB Output is correct
38 Correct 112 ms 7088 KB Output is correct
39 Correct 105 ms 7728 KB Output is correct
40 Correct 6 ms 724 KB Output is correct
41 Correct 20 ms 1780 KB Output is correct
42 Correct 4 ms 468 KB Output is correct
43 Correct 20 ms 1728 KB Output is correct
44 Correct 5 ms 596 KB Output is correct
45 Correct 24 ms 1812 KB Output is correct
46 Correct 110 ms 6580 KB Output is correct
47 Correct 95 ms 7076 KB Output is correct
48 Correct 90 ms 6712 KB Output is correct
49 Correct 110 ms 7868 KB Output is correct
50 Correct 100 ms 6580 KB Output is correct
51 Correct 106 ms 6836 KB Output is correct
52 Correct 89 ms 6536 KB Output is correct
53 Correct 113 ms 7864 KB Output is correct
54 Correct 101 ms 6576 KB Output is correct
55 Correct 92 ms 6684 KB Output is correct
56 Correct 121 ms 7856 KB Output is correct
57 Correct 113 ms 7980 KB Output is correct
58 Correct 94 ms 6696 KB Output is correct
59 Correct 97 ms 7220 KB Output is correct
60 Correct 139 ms 7716 KB Output is correct
61 Correct 135 ms 8012 KB Output is correct
62 Correct 90 ms 6444 KB Output is correct
63 Correct 113 ms 6692 KB Output is correct
64 Correct 125 ms 6960 KB Output is correct
65 Correct 117 ms 7732 KB Output is correct