#include <bits/stdc++.h>
using namespace std;
#define int long long
priority_queue<pair<int,int>> q;
vector<int> buildings[30001];
int power[30001];
set<int> visited;
int n;
inline void adddoge(int x,int building,int dist){
for(int i:visited)if(abs(building-i)%power[x]==0){
q.emplace(dist-(abs(building-i)/power[x]),i);
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int m;
cin >> n >> m;
int base,tar;
cin>>base>>power[0]>>tar>>power[1];
buildings[base].emplace_back(0);
buildings[tar].emplace_back(1);
for(int i=2;i<m;i++){
int b;cin>>b>>power[i];
buildings[b].emplace_back(i);
}
for(int i=0;i<n;i++)visited.insert(i);
q.emplace(0,base);
while(!q.empty()){
auto curr = q.top();q.pop();
if(visited.count(curr.second)==0)continue;
visited.erase(curr.second);
if(curr.second==tar){
cout << -curr.first << '\n';
return 0;
}
for(int&i:buildings[curr.second])adddoge(i,curr.second,curr.first);
}
cout << "-1\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1368 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1112 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
948 KB |
Output is correct |
5 |
Correct |
1 ms |
1112 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1200 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1112 KB |
Output is correct |
3 |
Correct |
1 ms |
1368 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1112 KB |
Output is correct |
11 |
Correct |
1 ms |
1112 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1184 KB |
Output is correct |
16 |
Correct |
1 ms |
1112 KB |
Output is correct |
17 |
Correct |
5 ms |
1624 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
301 ms |
19148 KB |
Output is correct |
21 |
Correct |
1 ms |
1112 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
5 ms |
1116 KB |
Output is correct |
24 |
Correct |
10 ms |
1372 KB |
Output is correct |
25 |
Correct |
5 ms |
1352 KB |
Output is correct |
26 |
Correct |
2 ms |
1116 KB |
Output is correct |
27 |
Correct |
2 ms |
1116 KB |
Output is correct |
28 |
Correct |
11 ms |
1344 KB |
Output is correct |
29 |
Correct |
17 ms |
2264 KB |
Output is correct |
30 |
Correct |
5 ms |
1628 KB |
Output is correct |
31 |
Correct |
9 ms |
1752 KB |
Output is correct |
32 |
Correct |
6 ms |
1628 KB |
Output is correct |
33 |
Correct |
40 ms |
3284 KB |
Output is correct |
34 |
Correct |
33 ms |
3280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
940 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
5 ms |
1516 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
285 ms |
19192 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
5 ms |
1116 KB |
Output is correct |
24 |
Correct |
10 ms |
1372 KB |
Output is correct |
25 |
Correct |
4 ms |
1116 KB |
Output is correct |
26 |
Correct |
1 ms |
1112 KB |
Output is correct |
27 |
Correct |
1 ms |
1112 KB |
Output is correct |
28 |
Correct |
11 ms |
1112 KB |
Output is correct |
29 |
Correct |
17 ms |
2264 KB |
Output is correct |
30 |
Correct |
5 ms |
1624 KB |
Output is correct |
31 |
Correct |
9 ms |
1752 KB |
Output is correct |
32 |
Correct |
6 ms |
1628 KB |
Output is correct |
33 |
Correct |
40 ms |
3328 KB |
Output is correct |
34 |
Correct |
33 ms |
3280 KB |
Output is correct |
35 |
Correct |
97 ms |
3016 KB |
Output is correct |
36 |
Correct |
5 ms |
1356 KB |
Output is correct |
37 |
Correct |
59 ms |
3860 KB |
Output is correct |
38 |
Correct |
173 ms |
4036 KB |
Output is correct |
39 |
Correct |
8 ms |
1884 KB |
Output is correct |
40 |
Correct |
40 ms |
2316 KB |
Output is correct |
41 |
Correct |
161 ms |
3988 KB |
Output is correct |
42 |
Correct |
4 ms |
1752 KB |
Output is correct |
43 |
Correct |
4 ms |
1756 KB |
Output is correct |
44 |
Correct |
305 ms |
18744 KB |
Output is correct |
45 |
Correct |
346 ms |
10040 KB |
Output is correct |
46 |
Correct |
319 ms |
12216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1112 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1112 KB |
Output is correct |
7 |
Correct |
1 ms |
1112 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
5 ms |
1628 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
270 ms |
19288 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1356 KB |
Output is correct |
23 |
Correct |
6 ms |
1116 KB |
Output is correct |
24 |
Correct |
11 ms |
1368 KB |
Output is correct |
25 |
Correct |
4 ms |
1360 KB |
Output is correct |
26 |
Correct |
1 ms |
1112 KB |
Output is correct |
27 |
Correct |
1 ms |
1116 KB |
Output is correct |
28 |
Correct |
11 ms |
1344 KB |
Output is correct |
29 |
Correct |
17 ms |
2264 KB |
Output is correct |
30 |
Correct |
5 ms |
1628 KB |
Output is correct |
31 |
Correct |
10 ms |
1748 KB |
Output is correct |
32 |
Correct |
6 ms |
1628 KB |
Output is correct |
33 |
Correct |
42 ms |
3284 KB |
Output is correct |
34 |
Correct |
33 ms |
3284 KB |
Output is correct |
35 |
Correct |
99 ms |
2772 KB |
Output is correct |
36 |
Correct |
5 ms |
1368 KB |
Output is correct |
37 |
Correct |
59 ms |
3756 KB |
Output is correct |
38 |
Correct |
203 ms |
3900 KB |
Output is correct |
39 |
Correct |
8 ms |
1880 KB |
Output is correct |
40 |
Correct |
52 ms |
2512 KB |
Output is correct |
41 |
Correct |
173 ms |
3816 KB |
Output is correct |
42 |
Correct |
6 ms |
1756 KB |
Output is correct |
43 |
Correct |
6 ms |
1780 KB |
Output is correct |
44 |
Correct |
313 ms |
19564 KB |
Output is correct |
45 |
Correct |
361 ms |
12140 KB |
Output is correct |
46 |
Correct |
335 ms |
11652 KB |
Output is correct |
47 |
Correct |
298 ms |
8360 KB |
Output is correct |
48 |
Correct |
9 ms |
2908 KB |
Output is correct |
49 |
Correct |
9 ms |
2808 KB |
Output is correct |
50 |
Correct |
7 ms |
2820 KB |
Output is correct |
51 |
Execution timed out |
1048 ms |
5500 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |