#include <iostream>
#include <set>
#include <queue>
#include <vector>
using namespace std;
set<int> v[2001];
vector<pair<int, int>> Q;
int n, m, q;
int M;
void bf(int k, int l) {
int viz[2001]{0};
queue<int> q;
viz[k] = 1;
q.push(k);
while (!q.empty()) {
for (auto m : v[q.front()]) {
if (!viz[m]) {
q.push(m);
viz[m] = viz[q.front()] + 1;
}
}
q.pop();
}
cout << viz[l] - 1 << '\n';
}
int main() {
cin >> n >> m >> q;
for (int i = 0; i < m; ++i) {
cin >> M;
v[M].insert(M+n);
v[M+n].insert(M);
}
for (int i = 0; i < 2*n; ++i) {
if (i == 0)
v[i].insert(2*n-1);
if (i == 2*n-1)
v[i].insert(0);
if (i < 2*n-1) v[i].insert(i+1);
if (i > 0) v[i].insert(i-1);
}
for (int i = 0; i < q; ++i) {
for (int j = 0; j < m; ++j) {
int a, b;
cin >> a >> b;
Q.push_back(make_pair(a, b));
}
}
for (auto p : Q) {
bf(p.first, p.second);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
860 KB |
Output is correct |
2 |
Correct |
13 ms |
788 KB |
Output is correct |
3 |
Correct |
51 ms |
872 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
7 ms |
604 KB |
Output is correct |
3 |
Correct |
8 ms |
628 KB |
Output is correct |
4 |
Incorrect |
3 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
7 ms |
604 KB |
Output is correct |
3 |
Correct |
8 ms |
628 KB |
Output is correct |
4 |
Incorrect |
3 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
860 KB |
Output is correct |
2 |
Correct |
13 ms |
788 KB |
Output is correct |
3 |
Correct |
51 ms |
872 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |