This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;
vector<set<int>> v;
long long n, m, q;
int M;
void bf(int k, int l) {
vector<int> viz(2*n);
queue<int> q;
viz[k] = 1;
q.push(k);
while (!q.empty()) {
int i = q.front();
if (i == 0)
v[i].insert(2LL*n-1);
if (i == 2LL*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 (auto m : v[q.front()]) {
if (!viz[m]) {
if (m == l) {
cout << viz[q.front()] << '\n';
return;
}
q.push(m);
viz[m] = viz[q.front()] + 1;
}
}
q.pop();
}
}
int main() {
cin.tie(NULL);
cin.sync_with_stdio(false);
cin >> n >> m >> q;
vector<set<int>> V(2LL*n);
v = V;
for (int i = 0; i < m; ++i) {
cin >> M;
v[M].insert(M+n);
v[M+n].insert(M);
}
for (int i = 0; i < q; ++i) {
int a, b;
cin >> a >> b;
bf(a, b);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |