Submission #639270

# Submission time Handle Problem Language Result Execution time Memory
639270 2022-09-09T07:40:25 Z NotLinux Autobus (COCI22_autobus) C++14
0 / 70
7 ms 368 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] = t;
    }
    for(int i = 0;i<n;i++)graph[i][i] = 0;
    int k,q;cin >> k >> q;
    for(int i = 0;i<k-1;i++){
        graph = opr(graph , graph);
    }
    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();
}

# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -