#include<iostream>
#include<vector>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<vector<int>> dist(n + 1, vector<int>(n + 1, 1e9));
int l, r;
for(int i = 1; i <= n; i++){
cin >> l >> r;
for(int j = l; j <= r; j++) dist[i][j] = 1;
dist[i][i] = 0;
}
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
int q;
cin >> q;
while(q--){
int a;
cin >> a;
int ans = 0;
for(int i = 1; i <= n; i++){
ans = max(ans, dist[a][i] + dist[i][1] + dist[1][n]);
}
if(ans == 1e9) cout << "-1\n";
else cout << ans << "\n";
}
}
// g++ -std=gnu++20 pC.cpp -o run -Wall -Wextra -fsanitize=undefined -fsanitize=address
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |