답안 #639283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639283 2022-09-09T08:18:54 Z NotLinux Autobus (COCI22_autobus) C++14
70 / 70
132 ms 6732 KB
/**
 * author: NotLinux
 * created: 09.09.2022 ~ 09:52:25
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
    #include "/home/notlinux/debug.h"
#else
    #define debug(x...) void(37)
#endif
int n,m;
const int inf = 1e18;
vector<vector<int>> opr(vector<vector<int>> &a , vector<vector<int>> &b){
    vector<vector<int>>c(n , vector < int > (n,inf));
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            for(int k = 0;k<n;k++){
                c[i][k] = min({c[i][k] , a[i][j] + b[j][k] , a[i][k]});
            }
        }
    }
    return c;
}
void solve(){
    cin >> n >> m;
    vector < vector < int > > graph(n , vector < int > (n,inf));
    for(int i = 0;i<m;i++){
        int a,b,t;cin >> a >> b >> t;
        graph[a-1][b-1] = min(graph[a-1][b-1],t);
    }
    for(int i = 0;i<n;i++)graph[i][i] = 0;
    vector<vector<int>>temp = graph;
    int k,q;cin >> k >> q;
    k = min({n-1 , k});
    for(int i = 0;i<k-1;i++){
        graph = opr(graph , temp);
    }
    while(q--){
        int l,r;cin >> l >> r;
        cout << (graph[l-1][r-1]==inf ? -1 : graph[l-1][r-1]) << endl;
    }
}
int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    int tt=1;
 //   cin >> tt;
    while(tt--)solve();
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 412 KB Output is correct
2 Correct 7 ms 468 KB Output is correct
3 Correct 8 ms 460 KB Output is correct
4 Correct 8 ms 564 KB Output is correct
5 Correct 9 ms 444 KB Output is correct
6 Correct 8 ms 468 KB Output is correct
7 Correct 12 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 19 ms 476 KB Output is correct
8 Correct 40 ms 424 KB Output is correct
9 Correct 8 ms 340 KB Output is correct
10 Correct 23 ms 420 KB Output is correct
11 Correct 12 ms 452 KB Output is correct
12 Correct 32 ms 340 KB Output is correct
13 Correct 93 ms 432 KB Output is correct
14 Correct 93 ms 352 KB Output is correct
15 Correct 117 ms 344 KB Output is correct
16 Correct 100 ms 424 KB Output is correct
17 Correct 95 ms 352 KB Output is correct
18 Correct 107 ms 388 KB Output is correct
19 Correct 127 ms 352 KB Output is correct
20 Correct 112 ms 428 KB Output is correct
21 Correct 100 ms 460 KB Output is correct
22 Correct 100 ms 460 KB Output is correct
23 Correct 97 ms 348 KB Output is correct
24 Correct 114 ms 352 KB Output is correct
25 Correct 113 ms 360 KB Output is correct
26 Correct 103 ms 340 KB Output is correct
27 Correct 103 ms 348 KB Output is correct
28 Correct 110 ms 596 KB Output is correct
29 Correct 93 ms 352 KB Output is correct
30 Correct 96 ms 340 KB Output is correct
31 Correct 109 ms 340 KB Output is correct
32 Correct 121 ms 420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 6 ms 412 KB Output is correct
8 Correct 7 ms 468 KB Output is correct
9 Correct 8 ms 460 KB Output is correct
10 Correct 8 ms 564 KB Output is correct
11 Correct 9 ms 444 KB Output is correct
12 Correct 8 ms 468 KB Output is correct
13 Correct 12 ms 444 KB Output is correct
14 Correct 19 ms 476 KB Output is correct
15 Correct 40 ms 424 KB Output is correct
16 Correct 8 ms 340 KB Output is correct
17 Correct 23 ms 420 KB Output is correct
18 Correct 12 ms 452 KB Output is correct
19 Correct 32 ms 340 KB Output is correct
20 Correct 93 ms 432 KB Output is correct
21 Correct 93 ms 352 KB Output is correct
22 Correct 117 ms 344 KB Output is correct
23 Correct 100 ms 424 KB Output is correct
24 Correct 95 ms 352 KB Output is correct
25 Correct 107 ms 388 KB Output is correct
26 Correct 127 ms 352 KB Output is correct
27 Correct 112 ms 428 KB Output is correct
28 Correct 100 ms 460 KB Output is correct
29 Correct 100 ms 460 KB Output is correct
30 Correct 97 ms 348 KB Output is correct
31 Correct 114 ms 352 KB Output is correct
32 Correct 113 ms 360 KB Output is correct
33 Correct 103 ms 340 KB Output is correct
34 Correct 103 ms 348 KB Output is correct
35 Correct 110 ms 596 KB Output is correct
36 Correct 93 ms 352 KB Output is correct
37 Correct 96 ms 340 KB Output is correct
38 Correct 109 ms 340 KB Output is correct
39 Correct 121 ms 420 KB Output is correct
40 Correct 14 ms 468 KB Output is correct
41 Correct 38 ms 432 KB Output is correct
42 Correct 10 ms 460 KB Output is correct
43 Correct 39 ms 484 KB Output is correct
44 Correct 12 ms 436 KB Output is correct
45 Correct 39 ms 520 KB Output is correct
46 Correct 104 ms 6600 KB Output is correct
47 Correct 114 ms 6476 KB Output is correct
48 Correct 103 ms 6604 KB Output is correct
49 Correct 132 ms 6480 KB Output is correct
50 Correct 104 ms 6604 KB Output is correct
51 Correct 106 ms 6612 KB Output is correct
52 Correct 98 ms 6568 KB Output is correct
53 Correct 127 ms 6612 KB Output is correct
54 Correct 97 ms 6612 KB Output is correct
55 Correct 98 ms 6608 KB Output is correct
56 Correct 126 ms 6608 KB Output is correct
57 Correct 128 ms 6692 KB Output is correct
58 Correct 99 ms 6728 KB Output is correct
59 Correct 111 ms 6732 KB Output is correct
60 Correct 130 ms 6732 KB Output is correct
61 Correct 129 ms 6728 KB Output is correct
62 Correct 95 ms 6484 KB Output is correct
63 Correct 101 ms 6472 KB Output is correct
64 Correct 110 ms 6556 KB Output is correct
65 Correct 126 ms 6532 KB Output is correct