#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class A, class B>
bool maximize(A &a, const B b) {
if (a < b) {
a = b;
return true;
} return false;
}
template <class A, class B>
bool minimize(A &a, const B b) {
if(a > b) {
a = b;
return true;
} return false;
}
using pII = pair <int, int>;
using vI = vector <int>;
using vL = vector <long long>;
using pLI = pair <long long, int>;
#define BIT(mask, i) ((mask >> (i)) & 1)
#define MASK(a) (1LL<<(a))
#define FOR(i, a, b) for(int i = a; i <= (int)b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int)b; i--)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
int n, m, q;
map <int, vector <int>> g;
ll dist[3005];
int calc(int x, int y) {
return min(abs(x - y), 2 * n - abs(x - y));
}
void process () {
cin >> n >> m >> q;
FOR(i, 1, m) {
int x; cin >> x;
g[x].push_back(n + x);
}
while(q--) {
int st, ed; cin >> st >> ed;
priority_queue <pLI, vector <pLI>, greater <pLI>> pq;
FOR(i, 0, 2 * n - 1) dist[i] = 1e18;
pq.push({dist[st] = 0, st});
while(sz(pq)) {
auto [cost, u] = pq.top();
pq.pop();
if(cost > dist[u]) continue;
for(int v : g[u]) if(dist[v] > cost + 1) {
dist[v] = cost + 1;
pq.push({dist[v], v});
}
if(1) {
int v = (u - 1 + 2 * n) % (2 * n);
if(dist[v] > cost + 1) {
dist[v] = cost + 1;
pq.push({dist[v], v});
}
}
if(1) {
int v = (u + 1) % (2 * n);
if(dist[v] > cost + 1) {
dist[v] = cost + 1;
pq.push({dist[v], v});
}
}
}
cout << dist[ed] << "\n";
}
}
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
#define taskname "kieuoanh"
if (fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
int tc = 1; /// cin >> tc;
while (tc--) process();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | freopen(taskname".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |