# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
696618 |
2023-02-07T01:33:40 Z |
uylulu |
Autobus (COCI22_autobus) |
C++17 |
|
138 ms |
4184 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int N = 70;
int dis[N + 1][N + 1],res[N + 1][N + 1][N + 1];
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int n,m;
cin>>n>>m;
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++) {
if(i == j) continue;
dis[i][j] = INT_MAX;
}
}
for(int i = 0;i < m;i++) {
int a,b,t;
cin>>a>>b>>t;
dis[a][b] = min(dis[a][b],t);
}
for(int i = 0;i <= n;i++) {
for(int j =0;j <= n;j++) {
for(int t = 0;t <= n;t++) {
res[i][j][t] = INT_MAX;
}
}
}
for(int i = 1;i <= n;i++) {
res[0][i][i] = 0;
}
for(int stage = 0;stage < n;stage++) {
for(int root = 1;root <= n;root++) {
for(int node = 1;node <= n;node++) {
for(int fin = 1;fin <= n;fin++) {
res[stage + 1][root][fin] = min(res[stage + 1][root][fin],res[stage][root][node] + dis[node][fin]);
}
}
}
}
int k,q;
cin>>k>>q;
k = min(k,n);
while(q--) {
int u,v;
cin>>u>>v;
int kq = INT_MAX;
for(int i = 0;i <= k;i++) {
kq = min(kq,res[i][u][v]);
}
if(kq == INT_MAX) {
cout<<-1<<endl;
} else {
cout<<kq<<endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
3156 KB |
Output is correct |
2 |
Correct |
26 ms |
3160 KB |
Output is correct |
3 |
Correct |
26 ms |
3156 KB |
Output is correct |
4 |
Correct |
25 ms |
3156 KB |
Output is correct |
5 |
Correct |
26 ms |
3160 KB |
Output is correct |
6 |
Correct |
25 ms |
3168 KB |
Output is correct |
7 |
Correct |
26 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
26 ms |
3164 KB |
Output is correct |
8 |
Correct |
26 ms |
3156 KB |
Output is correct |
9 |
Correct |
25 ms |
3156 KB |
Output is correct |
10 |
Correct |
30 ms |
3156 KB |
Output is correct |
11 |
Correct |
37 ms |
3156 KB |
Output is correct |
12 |
Correct |
28 ms |
3060 KB |
Output is correct |
13 |
Correct |
105 ms |
3052 KB |
Output is correct |
14 |
Correct |
103 ms |
3044 KB |
Output is correct |
15 |
Correct |
106 ms |
3052 KB |
Output is correct |
16 |
Correct |
104 ms |
3048 KB |
Output is correct |
17 |
Correct |
107 ms |
3048 KB |
Output is correct |
18 |
Correct |
108 ms |
3032 KB |
Output is correct |
19 |
Correct |
103 ms |
3040 KB |
Output is correct |
20 |
Correct |
110 ms |
3140 KB |
Output is correct |
21 |
Correct |
106 ms |
3180 KB |
Output is correct |
22 |
Correct |
107 ms |
3180 KB |
Output is correct |
23 |
Correct |
104 ms |
3164 KB |
Output is correct |
24 |
Correct |
105 ms |
3160 KB |
Output is correct |
25 |
Correct |
138 ms |
3048 KB |
Output is correct |
26 |
Correct |
107 ms |
3036 KB |
Output is correct |
27 |
Correct |
111 ms |
3044 KB |
Output is correct |
28 |
Correct |
107 ms |
3036 KB |
Output is correct |
29 |
Correct |
105 ms |
3044 KB |
Output is correct |
30 |
Correct |
104 ms |
3156 KB |
Output is correct |
31 |
Correct |
106 ms |
3164 KB |
Output is correct |
32 |
Correct |
126 ms |
3168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
25 ms |
3156 KB |
Output is correct |
8 |
Correct |
26 ms |
3160 KB |
Output is correct |
9 |
Correct |
26 ms |
3156 KB |
Output is correct |
10 |
Correct |
25 ms |
3156 KB |
Output is correct |
11 |
Correct |
26 ms |
3160 KB |
Output is correct |
12 |
Correct |
25 ms |
3168 KB |
Output is correct |
13 |
Correct |
26 ms |
3156 KB |
Output is correct |
14 |
Correct |
26 ms |
3164 KB |
Output is correct |
15 |
Correct |
26 ms |
3156 KB |
Output is correct |
16 |
Correct |
25 ms |
3156 KB |
Output is correct |
17 |
Correct |
30 ms |
3156 KB |
Output is correct |
18 |
Correct |
37 ms |
3156 KB |
Output is correct |
19 |
Correct |
28 ms |
3060 KB |
Output is correct |
20 |
Correct |
105 ms |
3052 KB |
Output is correct |
21 |
Correct |
103 ms |
3044 KB |
Output is correct |
22 |
Correct |
106 ms |
3052 KB |
Output is correct |
23 |
Correct |
104 ms |
3048 KB |
Output is correct |
24 |
Correct |
107 ms |
3048 KB |
Output is correct |
25 |
Correct |
108 ms |
3032 KB |
Output is correct |
26 |
Correct |
103 ms |
3040 KB |
Output is correct |
27 |
Correct |
110 ms |
3140 KB |
Output is correct |
28 |
Correct |
106 ms |
3180 KB |
Output is correct |
29 |
Correct |
107 ms |
3180 KB |
Output is correct |
30 |
Correct |
104 ms |
3164 KB |
Output is correct |
31 |
Correct |
105 ms |
3160 KB |
Output is correct |
32 |
Correct |
138 ms |
3048 KB |
Output is correct |
33 |
Correct |
107 ms |
3036 KB |
Output is correct |
34 |
Correct |
111 ms |
3044 KB |
Output is correct |
35 |
Correct |
107 ms |
3036 KB |
Output is correct |
36 |
Correct |
105 ms |
3044 KB |
Output is correct |
37 |
Correct |
104 ms |
3156 KB |
Output is correct |
38 |
Correct |
106 ms |
3164 KB |
Output is correct |
39 |
Correct |
126 ms |
3168 KB |
Output is correct |
40 |
Correct |
25 ms |
3156 KB |
Output is correct |
41 |
Correct |
26 ms |
3160 KB |
Output is correct |
42 |
Correct |
28 ms |
3156 KB |
Output is correct |
43 |
Correct |
32 ms |
3156 KB |
Output is correct |
44 |
Correct |
26 ms |
3168 KB |
Output is correct |
45 |
Correct |
26 ms |
3168 KB |
Output is correct |
46 |
Correct |
103 ms |
3140 KB |
Output is correct |
47 |
Correct |
109 ms |
3040 KB |
Output is correct |
48 |
Correct |
106 ms |
3032 KB |
Output is correct |
49 |
Correct |
105 ms |
3036 KB |
Output is correct |
50 |
Correct |
105 ms |
3032 KB |
Output is correct |
51 |
Correct |
105 ms |
3032 KB |
Output is correct |
52 |
Correct |
116 ms |
3040 KB |
Output is correct |
53 |
Correct |
107 ms |
3032 KB |
Output is correct |
54 |
Correct |
128 ms |
3160 KB |
Output is correct |
55 |
Correct |
105 ms |
3176 KB |
Output is correct |
56 |
Correct |
125 ms |
3168 KB |
Output is correct |
57 |
Correct |
108 ms |
3148 KB |
Output is correct |
58 |
Correct |
115 ms |
3032 KB |
Output is correct |
59 |
Correct |
110 ms |
3044 KB |
Output is correct |
60 |
Correct |
108 ms |
3044 KB |
Output is correct |
61 |
Correct |
111 ms |
3112 KB |
Output is correct |
62 |
Correct |
118 ms |
3160 KB |
Output is correct |
63 |
Correct |
118 ms |
3732 KB |
Output is correct |
64 |
Correct |
111 ms |
4168 KB |
Output is correct |
65 |
Correct |
124 ms |
4184 KB |
Output is correct |