This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
void apsp(vector<vector<int>> & matrizAdyacencia) {
int N = (int) matrizAdyacencia.size();
for (int k = 0; k < N; k++){
for (int i = 0; i < N; i++){
for (int j = 0; j < N; j++)
matrizAdyacencia[i][j] = min(matrizAdyacencia[i][j], matrizAdyacencia[i][k] + matrizAdyacencia[k][j]);
}
}
}
int main(){
int K, N, M, O, t, a, b;
cin >> K >> N >> M >> O;
vector<vector<int>> G(N, vector<int>(N, 1e9+7));
for(int i = 0; i < N; ++i)G[i][i] = 0;
for(int i = 0; i < M; ++i){
cin >> a >> b >> t;
G[a][b] = t;
}
apsp(G);
while(O--){
cin >> a >> b;
if(G[a][b] == 1e9+7) cout << -1 << endl;
else cout << G[a][b]<< endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |