/**
* 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;
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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
468 KB |
Output is correct |
3 |
Correct |
8 ms |
468 KB |
Output is correct |
4 |
Correct |
7 ms |
468 KB |
Output is correct |
5 |
Correct |
8 ms |
468 KB |
Output is correct |
6 |
Correct |
8 ms |
464 KB |
Output is correct |
7 |
Correct |
8 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
18 ms |
480 KB |
Output is correct |
8 |
Correct |
41 ms |
468 KB |
Output is correct |
9 |
Correct |
11 ms |
496 KB |
Output is correct |
10 |
Correct |
24 ms |
468 KB |
Output is correct |
11 |
Correct |
12 ms |
500 KB |
Output is correct |
12 |
Correct |
29 ms |
444 KB |
Output is correct |
13 |
Correct |
95 ms |
6480 KB |
Output is correct |
14 |
Correct |
103 ms |
6480 KB |
Output is correct |
15 |
Correct |
125 ms |
6480 KB |
Output is correct |
16 |
Correct |
107 ms |
6476 KB |
Output is correct |
17 |
Correct |
95 ms |
6608 KB |
Output is correct |
18 |
Correct |
104 ms |
6620 KB |
Output is correct |
19 |
Correct |
132 ms |
6656 KB |
Output is correct |
20 |
Correct |
118 ms |
6596 KB |
Output is correct |
21 |
Correct |
109 ms |
6596 KB |
Output is correct |
22 |
Correct |
103 ms |
6608 KB |
Output is correct |
23 |
Correct |
107 ms |
6612 KB |
Output is correct |
24 |
Correct |
111 ms |
6604 KB |
Output is correct |
25 |
Correct |
98 ms |
6732 KB |
Output is correct |
26 |
Correct |
102 ms |
6732 KB |
Output is correct |
27 |
Correct |
110 ms |
6988 KB |
Output is correct |
28 |
Correct |
107 ms |
6740 KB |
Output is correct |
29 |
Correct |
98 ms |
6476 KB |
Output is correct |
30 |
Correct |
104 ms |
6476 KB |
Output is correct |
31 |
Correct |
113 ms |
6468 KB |
Output is correct |
32 |
Correct |
126 ms |
6472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
7 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
468 KB |
Output is correct |
9 |
Correct |
8 ms |
468 KB |
Output is correct |
10 |
Correct |
7 ms |
468 KB |
Output is correct |
11 |
Correct |
8 ms |
468 KB |
Output is correct |
12 |
Correct |
8 ms |
464 KB |
Output is correct |
13 |
Correct |
8 ms |
468 KB |
Output is correct |
14 |
Correct |
18 ms |
480 KB |
Output is correct |
15 |
Correct |
41 ms |
468 KB |
Output is correct |
16 |
Correct |
11 ms |
496 KB |
Output is correct |
17 |
Correct |
24 ms |
468 KB |
Output is correct |
18 |
Correct |
12 ms |
500 KB |
Output is correct |
19 |
Correct |
29 ms |
444 KB |
Output is correct |
20 |
Correct |
95 ms |
6480 KB |
Output is correct |
21 |
Correct |
103 ms |
6480 KB |
Output is correct |
22 |
Correct |
125 ms |
6480 KB |
Output is correct |
23 |
Correct |
107 ms |
6476 KB |
Output is correct |
24 |
Correct |
95 ms |
6608 KB |
Output is correct |
25 |
Correct |
104 ms |
6620 KB |
Output is correct |
26 |
Correct |
132 ms |
6656 KB |
Output is correct |
27 |
Correct |
118 ms |
6596 KB |
Output is correct |
28 |
Correct |
109 ms |
6596 KB |
Output is correct |
29 |
Correct |
103 ms |
6608 KB |
Output is correct |
30 |
Correct |
107 ms |
6612 KB |
Output is correct |
31 |
Correct |
111 ms |
6604 KB |
Output is correct |
32 |
Correct |
98 ms |
6732 KB |
Output is correct |
33 |
Correct |
102 ms |
6732 KB |
Output is correct |
34 |
Correct |
110 ms |
6988 KB |
Output is correct |
35 |
Correct |
107 ms |
6740 KB |
Output is correct |
36 |
Correct |
98 ms |
6476 KB |
Output is correct |
37 |
Correct |
104 ms |
6476 KB |
Output is correct |
38 |
Correct |
113 ms |
6468 KB |
Output is correct |
39 |
Correct |
126 ms |
6472 KB |
Output is correct |
40 |
Correct |
15 ms |
492 KB |
Output is correct |
41 |
Execution timed out |
1088 ms |
468 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |