#include <iostream>
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define pii pair<int, int>
#define fst first
#define snd second
#define vi vector<int>
#define vpi vector<pii>
#define pub push_back
using namespace std;
const int MX = 1e9;
int n, m, s, e, dst[30001] = {};
vpi adj[30001];
unordered_set<int> edgeQuery[30001];
priority_queue<pii, vector<pii>, greater<pii>> pq;
int temp[30001] = {}, tpsz = 0;
inline int dijkstra()
{
pq.push({0, s});
dst[s] = 0;
while (pq.size())
{
pii dt = pq.top(); pq.pop();
if (dst[dt.snd] == dt.fst)
{
//cout << "DIK : " << dt.snd << ", " << dt.fst << "\n";
if (dt.snd == e) {return dt.fst;}
for (auto v : adj[dt.snd])
{
if (dt.fst + v.snd < dst[v.fst])
{
dst[v.fst] = dt.fst + v.snd;
pq.push({dt.fst + v.snd, v.fst});
}
}
}
}
return -1;
}
int main()
{
// ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++)
{
dst[i] = MX;
}
for (int i = 0; i < m; i++)
{
int u, t; cin >> u >> t;
edgeQuery[u].insert(t);
if (i == 0) s = u;
else if (i == 1) e = u;
}
for (int i = 0; i < n; i++)
{
while (edgeQuery[i].size())
{
int x = *edgeQuery[i].begin(), s = i % x, lst = -1, cnt = 0;
for (; s < n; s += x)
{
if (edgeQuery[s].count(x))
{
edgeQuery[s].erase(x);
if (lst >= 0)
{
adj[lst].push_back({s, cnt});
adj[s].push_back({lst, cnt});
}
lst = s; cnt = 1;
for (int i = tpsz - 1; i >= 0; i--)
{
adj[s].push_back({temp[i], cnt});
cnt++;
}
tpsz = 0;
cnt = 0;
}
else
{
if (lst >= 0)
{
adj[lst].push_back({s, cnt});
}
temp[tpsz++] = s;
}
cnt++;
}
tpsz = 0;
}
}
/*
for (int i = 0; i < n; i++)
{
cout << i << "-th node adjacency list :\n";
for (auto x : adj[i])
{
cout << x.fst << ", " << x.snd << '\n';
}
}
cout << "Here\n";
*/
cout << dijkstra() << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
8 ms |
2688 KB |
Output is correct |
5 |
Correct |
7 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
7 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
8 ms |
2816 KB |
Output is correct |
12 |
Correct |
7 ms |
2688 KB |
Output is correct |
13 |
Correct |
7 ms |
2688 KB |
Output is correct |
14 |
Correct |
8 ms |
2816 KB |
Output is correct |
15 |
Correct |
9 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
7 ms |
2688 KB |
Output is correct |
10 |
Correct |
7 ms |
2688 KB |
Output is correct |
11 |
Correct |
9 ms |
2816 KB |
Output is correct |
12 |
Correct |
8 ms |
2688 KB |
Output is correct |
13 |
Correct |
7 ms |
2688 KB |
Output is correct |
14 |
Correct |
7 ms |
2816 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
16 |
Correct |
7 ms |
2688 KB |
Output is correct |
17 |
Correct |
9 ms |
2944 KB |
Output is correct |
18 |
Correct |
7 ms |
2816 KB |
Output is correct |
19 |
Correct |
6 ms |
2816 KB |
Output is correct |
20 |
Correct |
8 ms |
2816 KB |
Output is correct |
21 |
Correct |
7 ms |
2688 KB |
Output is correct |
22 |
Correct |
8 ms |
2816 KB |
Output is correct |
23 |
Correct |
8 ms |
2816 KB |
Output is correct |
24 |
Correct |
8 ms |
2944 KB |
Output is correct |
25 |
Correct |
9 ms |
2868 KB |
Output is correct |
26 |
Correct |
8 ms |
2816 KB |
Output is correct |
27 |
Correct |
8 ms |
2816 KB |
Output is correct |
28 |
Correct |
9 ms |
3072 KB |
Output is correct |
29 |
Correct |
11 ms |
3584 KB |
Output is correct |
30 |
Correct |
7 ms |
3072 KB |
Output is correct |
31 |
Correct |
8 ms |
3200 KB |
Output is correct |
32 |
Correct |
8 ms |
3072 KB |
Output is correct |
33 |
Correct |
14 ms |
4096 KB |
Output is correct |
34 |
Correct |
11 ms |
4096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Correct |
7 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2648 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
7 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
7 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
9 ms |
2816 KB |
Output is correct |
12 |
Correct |
7 ms |
2688 KB |
Output is correct |
13 |
Correct |
7 ms |
2816 KB |
Output is correct |
14 |
Correct |
8 ms |
2816 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
16 |
Correct |
7 ms |
2688 KB |
Output is correct |
17 |
Correct |
8 ms |
2944 KB |
Output is correct |
18 |
Correct |
7 ms |
2816 KB |
Output is correct |
19 |
Correct |
7 ms |
2816 KB |
Output is correct |
20 |
Correct |
8 ms |
2816 KB |
Output is correct |
21 |
Correct |
7 ms |
2816 KB |
Output is correct |
22 |
Correct |
7 ms |
2816 KB |
Output is correct |
23 |
Correct |
7 ms |
2816 KB |
Output is correct |
24 |
Correct |
9 ms |
2944 KB |
Output is correct |
25 |
Correct |
9 ms |
2944 KB |
Output is correct |
26 |
Correct |
7 ms |
2816 KB |
Output is correct |
27 |
Correct |
8 ms |
2816 KB |
Output is correct |
28 |
Correct |
9 ms |
3072 KB |
Output is correct |
29 |
Correct |
9 ms |
3584 KB |
Output is correct |
30 |
Correct |
7 ms |
3072 KB |
Output is correct |
31 |
Correct |
8 ms |
3200 KB |
Output is correct |
32 |
Correct |
7 ms |
3072 KB |
Output is correct |
33 |
Correct |
11 ms |
4096 KB |
Output is correct |
34 |
Correct |
11 ms |
4224 KB |
Output is correct |
35 |
Correct |
34 ms |
4992 KB |
Output is correct |
36 |
Correct |
11 ms |
3072 KB |
Output is correct |
37 |
Correct |
31 ms |
5624 KB |
Output is correct |
38 |
Correct |
41 ms |
5624 KB |
Output is correct |
39 |
Correct |
44 ms |
5752 KB |
Output is correct |
40 |
Correct |
41 ms |
5624 KB |
Output is correct |
41 |
Correct |
41 ms |
5752 KB |
Output is correct |
42 |
Correct |
25 ms |
2944 KB |
Output is correct |
43 |
Correct |
24 ms |
2936 KB |
Output is correct |
44 |
Correct |
24 ms |
2944 KB |
Output is correct |
45 |
Correct |
46 ms |
8184 KB |
Output is correct |
46 |
Correct |
43 ms |
8312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
7 ms |
2688 KB |
Output is correct |
11 |
Correct |
8 ms |
2816 KB |
Output is correct |
12 |
Correct |
7 ms |
2688 KB |
Output is correct |
13 |
Correct |
7 ms |
2688 KB |
Output is correct |
14 |
Correct |
7 ms |
2816 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
16 |
Correct |
7 ms |
2688 KB |
Output is correct |
17 |
Correct |
9 ms |
2944 KB |
Output is correct |
18 |
Correct |
7 ms |
2816 KB |
Output is correct |
19 |
Correct |
7 ms |
2816 KB |
Output is correct |
20 |
Correct |
8 ms |
2816 KB |
Output is correct |
21 |
Correct |
7 ms |
2688 KB |
Output is correct |
22 |
Correct |
7 ms |
2816 KB |
Output is correct |
23 |
Correct |
8 ms |
2816 KB |
Output is correct |
24 |
Correct |
8 ms |
2944 KB |
Output is correct |
25 |
Correct |
8 ms |
2816 KB |
Output is correct |
26 |
Correct |
8 ms |
2816 KB |
Output is correct |
27 |
Correct |
8 ms |
2816 KB |
Output is correct |
28 |
Correct |
9 ms |
3072 KB |
Output is correct |
29 |
Correct |
9 ms |
3584 KB |
Output is correct |
30 |
Correct |
7 ms |
2944 KB |
Output is correct |
31 |
Correct |
9 ms |
3200 KB |
Output is correct |
32 |
Correct |
7 ms |
3072 KB |
Output is correct |
33 |
Correct |
11 ms |
4096 KB |
Output is correct |
34 |
Correct |
11 ms |
4096 KB |
Output is correct |
35 |
Correct |
36 ms |
4856 KB |
Output is correct |
36 |
Correct |
11 ms |
3072 KB |
Output is correct |
37 |
Correct |
30 ms |
5624 KB |
Output is correct |
38 |
Correct |
41 ms |
5624 KB |
Output is correct |
39 |
Correct |
40 ms |
5624 KB |
Output is correct |
40 |
Correct |
40 ms |
5624 KB |
Output is correct |
41 |
Correct |
40 ms |
5624 KB |
Output is correct |
42 |
Correct |
25 ms |
3072 KB |
Output is correct |
43 |
Correct |
24 ms |
2944 KB |
Output is correct |
44 |
Correct |
24 ms |
2944 KB |
Output is correct |
45 |
Correct |
43 ms |
8184 KB |
Output is correct |
46 |
Correct |
41 ms |
8312 KB |
Output is correct |
47 |
Correct |
63 ms |
13044 KB |
Output is correct |
48 |
Correct |
39 ms |
6264 KB |
Output is correct |
49 |
Correct |
35 ms |
5240 KB |
Output is correct |
50 |
Correct |
28 ms |
5120 KB |
Output is correct |
51 |
Correct |
62 ms |
8196 KB |
Output is correct |
52 |
Correct |
64 ms |
8628 KB |
Output is correct |
53 |
Correct |
45 ms |
5620 KB |
Output is correct |
54 |
Correct |
8 ms |
3328 KB |
Output is correct |
55 |
Correct |
9 ms |
3836 KB |
Output is correct |
56 |
Correct |
36 ms |
4864 KB |
Output is correct |
57 |
Correct |
28 ms |
11640 KB |
Output is correct |
58 |
Correct |
23 ms |
4088 KB |
Output is correct |
59 |
Correct |
30 ms |
4496 KB |
Output is correct |
60 |
Correct |
29 ms |
5132 KB |
Output is correct |
61 |
Correct |
33 ms |
4344 KB |
Output is correct |
62 |
Correct |
59 ms |
9972 KB |
Output is correct |
63 |
Correct |
108 ms |
25236 KB |
Output is correct |
64 |
Correct |
128 ms |
28800 KB |
Output is correct |
65 |
Correct |
144 ms |
39404 KB |
Output is correct |
66 |
Correct |
217 ms |
65488 KB |
Output is correct |
67 |
Correct |
208 ms |
65516 KB |
Output is correct |