# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
705909 |
2023-03-05T15:53:03 Z |
Gital |
Autobus (COCI22_autobus) |
C++11 |
|
386 ms |
9676 KB |
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
ll n,m,a,b,w;
ll k,q,c,d;
ll adj[72][72];
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
ll dp[72][72][72];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++) {
cin >> a >> b >> w;
if(adj[a][b] == 0 || adj[a][b] > w)adj[a][b] = w;
}
cin >> k >> q;
if(k > 70) k = 70;
for(int i = 0; i < 71; i++) {
for(int j = 0; j < 71; j++) {
for(int l= 0; l < 71; l++) dp[i][j][l] = -1;
}
}
for(int j = 1; j <= n; j++) {
pq.push({0,j});
for(int i = 0; i < 72; i++) dp[j][j][i] = 0;
while(!pq.empty()) {
a = pq.top().first;
b = pq.top().second;
pq.pop();
for(int i = 1; i <= n; i++) {
bool able = false;
if(adj[b][i] == 0) continue;
for(int l = a; l < k; l++) {
if(dp[j][b][l] != -1 && (dp[j][i][l + 1] == -1 || dp[j][i][l + 1] > dp[j][b][l] + adj[b][i])) {
dp[j][i][l + 1] = dp[j][b][l] + adj[b][i];
if(!able) pq.push({l + 1,i});
able = true;
}
}
}
}
}
/*for(int i = 1; i < 5; i++) {
cout << "i = " << i << endl;
for(int j = 1; j < 5; j++) {
cout << "j = " << j << endl;
for(int l= 0; l < 2; l++) {
cout << dp[i][j][l] << ' ';
}
cout << endl;
}
}*/
for(int i = 0; i < q; i++) {
cin >> c >> d;
cout << dp[c][d][k] << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Correct |
2 ms |
3156 KB |
Output is correct |
4 |
Correct |
2 ms |
3156 KB |
Output is correct |
5 |
Correct |
2 ms |
3156 KB |
Output is correct |
6 |
Correct |
2 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3280 KB |
Output is correct |
2 |
Correct |
4 ms |
3284 KB |
Output is correct |
3 |
Correct |
6 ms |
3288 KB |
Output is correct |
4 |
Correct |
7 ms |
3284 KB |
Output is correct |
5 |
Correct |
7 ms |
3284 KB |
Output is correct |
6 |
Correct |
9 ms |
3340 KB |
Output is correct |
7 |
Correct |
15 ms |
3332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Correct |
2 ms |
3156 KB |
Output is correct |
4 |
Correct |
2 ms |
3156 KB |
Output is correct |
5 |
Correct |
2 ms |
3156 KB |
Output is correct |
6 |
Correct |
2 ms |
3156 KB |
Output is correct |
7 |
Correct |
9 ms |
3284 KB |
Output is correct |
8 |
Correct |
16 ms |
3284 KB |
Output is correct |
9 |
Correct |
8 ms |
3284 KB |
Output is correct |
10 |
Correct |
21 ms |
3288 KB |
Output is correct |
11 |
Correct |
36 ms |
3320 KB |
Output is correct |
12 |
Correct |
126 ms |
3320 KB |
Output is correct |
13 |
Correct |
105 ms |
8820 KB |
Output is correct |
14 |
Correct |
110 ms |
9288 KB |
Output is correct |
15 |
Correct |
272 ms |
9420 KB |
Output is correct |
16 |
Correct |
149 ms |
9388 KB |
Output is correct |
17 |
Correct |
128 ms |
9424 KB |
Output is correct |
18 |
Correct |
93 ms |
9420 KB |
Output is correct |
19 |
Correct |
244 ms |
9456 KB |
Output is correct |
20 |
Correct |
194 ms |
9428 KB |
Output is correct |
21 |
Correct |
92 ms |
9432 KB |
Output is correct |
22 |
Correct |
112 ms |
9432 KB |
Output is correct |
23 |
Correct |
107 ms |
9476 KB |
Output is correct |
24 |
Correct |
160 ms |
9404 KB |
Output is correct |
25 |
Correct |
99 ms |
9548 KB |
Output is correct |
26 |
Correct |
124 ms |
9580 KB |
Output is correct |
27 |
Correct |
145 ms |
9576 KB |
Output is correct |
28 |
Correct |
141 ms |
9592 KB |
Output is correct |
29 |
Correct |
103 ms |
9280 KB |
Output is correct |
30 |
Correct |
150 ms |
9320 KB |
Output is correct |
31 |
Correct |
234 ms |
9292 KB |
Output is correct |
32 |
Correct |
380 ms |
9328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Correct |
2 ms |
3156 KB |
Output is correct |
4 |
Correct |
2 ms |
3156 KB |
Output is correct |
5 |
Correct |
2 ms |
3156 KB |
Output is correct |
6 |
Correct |
2 ms |
3156 KB |
Output is correct |
7 |
Correct |
4 ms |
3280 KB |
Output is correct |
8 |
Correct |
4 ms |
3284 KB |
Output is correct |
9 |
Correct |
6 ms |
3288 KB |
Output is correct |
10 |
Correct |
7 ms |
3284 KB |
Output is correct |
11 |
Correct |
7 ms |
3284 KB |
Output is correct |
12 |
Correct |
9 ms |
3340 KB |
Output is correct |
13 |
Correct |
15 ms |
3332 KB |
Output is correct |
14 |
Correct |
9 ms |
3284 KB |
Output is correct |
15 |
Correct |
16 ms |
3284 KB |
Output is correct |
16 |
Correct |
8 ms |
3284 KB |
Output is correct |
17 |
Correct |
21 ms |
3288 KB |
Output is correct |
18 |
Correct |
36 ms |
3320 KB |
Output is correct |
19 |
Correct |
126 ms |
3320 KB |
Output is correct |
20 |
Correct |
105 ms |
8820 KB |
Output is correct |
21 |
Correct |
110 ms |
9288 KB |
Output is correct |
22 |
Correct |
272 ms |
9420 KB |
Output is correct |
23 |
Correct |
149 ms |
9388 KB |
Output is correct |
24 |
Correct |
128 ms |
9424 KB |
Output is correct |
25 |
Correct |
93 ms |
9420 KB |
Output is correct |
26 |
Correct |
244 ms |
9456 KB |
Output is correct |
27 |
Correct |
194 ms |
9428 KB |
Output is correct |
28 |
Correct |
92 ms |
9432 KB |
Output is correct |
29 |
Correct |
112 ms |
9432 KB |
Output is correct |
30 |
Correct |
107 ms |
9476 KB |
Output is correct |
31 |
Correct |
160 ms |
9404 KB |
Output is correct |
32 |
Correct |
99 ms |
9548 KB |
Output is correct |
33 |
Correct |
124 ms |
9580 KB |
Output is correct |
34 |
Correct |
145 ms |
9576 KB |
Output is correct |
35 |
Correct |
141 ms |
9592 KB |
Output is correct |
36 |
Correct |
103 ms |
9280 KB |
Output is correct |
37 |
Correct |
150 ms |
9320 KB |
Output is correct |
38 |
Correct |
234 ms |
9292 KB |
Output is correct |
39 |
Correct |
380 ms |
9328 KB |
Output is correct |
40 |
Correct |
8 ms |
3284 KB |
Output is correct |
41 |
Correct |
15 ms |
3264 KB |
Output is correct |
42 |
Correct |
11 ms |
3284 KB |
Output is correct |
43 |
Correct |
33 ms |
3288 KB |
Output is correct |
44 |
Correct |
33 ms |
3328 KB |
Output is correct |
45 |
Correct |
167 ms |
3260 KB |
Output is correct |
46 |
Correct |
102 ms |
9292 KB |
Output is correct |
47 |
Correct |
195 ms |
9384 KB |
Output is correct |
48 |
Correct |
133 ms |
9420 KB |
Output is correct |
49 |
Correct |
316 ms |
9292 KB |
Output is correct |
50 |
Correct |
103 ms |
9420 KB |
Output is correct |
51 |
Correct |
126 ms |
9424 KB |
Output is correct |
52 |
Correct |
89 ms |
9420 KB |
Output is correct |
53 |
Correct |
236 ms |
9548 KB |
Output is correct |
54 |
Correct |
96 ms |
9432 KB |
Output is correct |
55 |
Correct |
101 ms |
9428 KB |
Output is correct |
56 |
Correct |
211 ms |
9432 KB |
Output is correct |
57 |
Correct |
230 ms |
9420 KB |
Output is correct |
58 |
Correct |
93 ms |
9544 KB |
Output is correct |
59 |
Correct |
181 ms |
9592 KB |
Output is correct |
60 |
Correct |
239 ms |
9676 KB |
Output is correct |
61 |
Correct |
312 ms |
9564 KB |
Output is correct |
62 |
Correct |
94 ms |
9288 KB |
Output is correct |
63 |
Correct |
155 ms |
9296 KB |
Output is correct |
64 |
Correct |
168 ms |
9292 KB |
Output is correct |
65 |
Correct |
386 ms |
9420 KB |
Output is correct |