답안 #639281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639281 2022-09-09T08:11:21 Z NotLinux Autobus (COCI22_autobus) C++14
0 / 70
7 ms 452 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;
    vector<vector<int>>temp = graph;
    int k,q;cin >> k >> q;
    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 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -