#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
int n, m, q;
vector<vector<int>> ad;
vector<int> dist;
void bfs(int k)
{
dist = vector<int>(2*n);
dist[k]=1;
queue<int> q;
q.push(k);
while(!q.empty())
{
int node=q.front();
q.pop();
for(auto& x : ad[node])
{
if(!dist[x])
{
dist[x]=dist[node]+1;
q.push(x);
}
}
}
}
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>n>>m>>q;
ad = vector<vector<int>>(2*n);
for(int i=0; i<2*n-1; i++)
{
ad[i].push_back(i+1);
ad[i+1].push_back(i);
}
ad[2*n-1].push_back(0);
ad[0].push_back(2*n-1);
for(int i=0; i<m; i++)
{
int k;
cin>>k;
ad[k].push_back(k+n);
ad[k+n].push_back(k);
}
for(int i=1; i<=q; i++)
{
int x, y;
cin>>x>>y;
bfs(x);
cout<<dist[y]-1<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
7 ms |
348 KB |
Output is correct |
3 |
Correct |
21 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Execution timed out |
2100 ms |
12892 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
5 ms |
348 KB |
Output is correct |
8 |
Correct |
10 ms |
348 KB |
Output is correct |
9 |
Correct |
11 ms |
344 KB |
Output is correct |
10 |
Correct |
9 ms |
580 KB |
Output is correct |
11 |
Correct |
10 ms |
580 KB |
Output is correct |
12 |
Correct |
10 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
588 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
5 ms |
348 KB |
Output is correct |
8 |
Correct |
10 ms |
348 KB |
Output is correct |
9 |
Correct |
11 ms |
344 KB |
Output is correct |
10 |
Correct |
9 ms |
580 KB |
Output is correct |
11 |
Correct |
10 ms |
580 KB |
Output is correct |
12 |
Correct |
10 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
588 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
348 KB |
Output is correct |
23 |
Correct |
5 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
4 ms |
348 KB |
Output is correct |
28 |
Correct |
10 ms |
348 KB |
Output is correct |
29 |
Correct |
11 ms |
348 KB |
Output is correct |
30 |
Correct |
10 ms |
344 KB |
Output is correct |
31 |
Correct |
10 ms |
348 KB |
Output is correct |
32 |
Correct |
10 ms |
348 KB |
Output is correct |
33 |
Correct |
15 ms |
588 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Execution timed out |
2067 ms |
844472 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
7 ms |
348 KB |
Output is correct |
3 |
Correct |
21 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Execution timed out |
2100 ms |
12892 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |