#include <iostream>
#include <vector>
using namespace std;
struct event {
int s, e;
};
int n, q, a, b;
vector <event> v(5001);
vector <vector <int>> g(1e5 + 1);
vector <vector <int>> d(5001, vector <int>(5001, 1e9));
vector <bool> done(5001, false);
void dfs(int x) {
if (done[x]) return;
done[x] = true;
for (int i : g[x]) {
dfs(i);
for (int j = 1; j <= n; j++) d[x][j] = min(d[x][j], d[i][j] + 1);
}
}
int main()
{
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> v[i].s >> v[i].e;
d[i][i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (v[i].e >= v[j].s && v[i].e < v[j].e) g[i].push_back(j);
if (v[i].e == v[j].e && v[i].s < v[j].s) g[i].push_back(j);
}
}
for (int i = 1; i <= n; i++) dfs(i);
for (int i = 0; i < q; i++) {
cin >> a >> b;
if (d[a][b] < 1e9) cout << d[a][b] << "\n";
else cout << "impossible\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
100684 KB |
Output is correct |
2 |
Runtime error |
154 ms |
204084 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
100640 KB |
Output is correct |
2 |
Correct |
48 ms |
100688 KB |
Output is correct |
3 |
Correct |
52 ms |
100776 KB |
Output is correct |
4 |
Correct |
55 ms |
100776 KB |
Output is correct |
5 |
Correct |
55 ms |
100760 KB |
Output is correct |
6 |
Correct |
205 ms |
101472 KB |
Output is correct |
7 |
Correct |
379 ms |
102476 KB |
Output is correct |
8 |
Correct |
599 ms |
103420 KB |
Output is correct |
9 |
Incorrect |
54 ms |
100716 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
100640 KB |
Output is correct |
2 |
Correct |
48 ms |
100688 KB |
Output is correct |
3 |
Correct |
52 ms |
100776 KB |
Output is correct |
4 |
Correct |
55 ms |
100776 KB |
Output is correct |
5 |
Correct |
55 ms |
100760 KB |
Output is correct |
6 |
Correct |
205 ms |
101472 KB |
Output is correct |
7 |
Correct |
379 ms |
102476 KB |
Output is correct |
8 |
Correct |
599 ms |
103420 KB |
Output is correct |
9 |
Incorrect |
54 ms |
100716 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
100640 KB |
Output is correct |
2 |
Correct |
48 ms |
100688 KB |
Output is correct |
3 |
Correct |
52 ms |
100776 KB |
Output is correct |
4 |
Correct |
55 ms |
100776 KB |
Output is correct |
5 |
Correct |
55 ms |
100760 KB |
Output is correct |
6 |
Correct |
205 ms |
101472 KB |
Output is correct |
7 |
Correct |
379 ms |
102476 KB |
Output is correct |
8 |
Correct |
599 ms |
103420 KB |
Output is correct |
9 |
Incorrect |
54 ms |
100716 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
139 ms |
204080 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
100684 KB |
Output is correct |
2 |
Runtime error |
154 ms |
204084 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |