#include <bits/stdc++.h>
using namespace std;
vector<vector<int>>g;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
g.resize(n + 1);
vector<pair<int, int>>events(n + 1);
for(int i = 1;i <= n;++i){
cin >> events[i].first >> events[i].second;
}
for(int i = 1;i <= n;++i){
for(int j = 1;j <= n;++j){
if(i == j)continue;
if(events[i].second >= events[j].first && events[i].second <= events[j].second){
g[i].push_back(j);
}
}
}
// for(int i = 1;i <= n;++i){
// cout << i << ": ";
// for(int j : g[i]){
// cout << j << " ";
// }
// cout << '\n';
// }
vector<vector<int>>dist(n + 1, vector<int>(n + 1, -1));
for(int i = 1;i <= n;++i){
dist[i][i] = 0;
queue<int>q;
q.push(i);
while(!q.empty()){
int cur = q.front();
q.pop();
for(int v : g[cur]){
if(dist[i][v] == -1){
dist[i][v] = dist[i][cur] + 1;
q.push(v);
}
}
}
}
while(q--){
int u, v;
cin >> u >> v;
if(dist[u][v] == -1)cout << "impossible\n";
else cout << dist[u][v] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1572 ms |
3660 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
16 ms |
4284 KB |
Output is correct |
4 |
Correct |
11 ms |
4308 KB |
Output is correct |
5 |
Correct |
16 ms |
4308 KB |
Output is correct |
6 |
Correct |
56 ms |
5100 KB |
Output is correct |
7 |
Correct |
159 ms |
5912 KB |
Output is correct |
8 |
Correct |
217 ms |
6868 KB |
Output is correct |
9 |
Correct |
1085 ms |
8332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
16 ms |
4284 KB |
Output is correct |
4 |
Correct |
11 ms |
4308 KB |
Output is correct |
5 |
Correct |
16 ms |
4308 KB |
Output is correct |
6 |
Correct |
56 ms |
5100 KB |
Output is correct |
7 |
Correct |
159 ms |
5912 KB |
Output is correct |
8 |
Correct |
217 ms |
6868 KB |
Output is correct |
9 |
Correct |
1085 ms |
8332 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
16 ms |
4308 KB |
Output is correct |
13 |
Correct |
12 ms |
4308 KB |
Output is correct |
14 |
Correct |
19 ms |
4332 KB |
Output is correct |
15 |
Correct |
75 ms |
5016 KB |
Output is correct |
16 |
Correct |
163 ms |
5876 KB |
Output is correct |
17 |
Correct |
196 ms |
6968 KB |
Output is correct |
18 |
Correct |
1165 ms |
8324 KB |
Output is correct |
19 |
Execution timed out |
1581 ms |
128404 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
16 ms |
4284 KB |
Output is correct |
4 |
Correct |
11 ms |
4308 KB |
Output is correct |
5 |
Correct |
16 ms |
4308 KB |
Output is correct |
6 |
Correct |
56 ms |
5100 KB |
Output is correct |
7 |
Correct |
159 ms |
5912 KB |
Output is correct |
8 |
Correct |
217 ms |
6868 KB |
Output is correct |
9 |
Correct |
1085 ms |
8332 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
17 ms |
4336 KB |
Output is correct |
13 |
Correct |
12 ms |
4308 KB |
Output is correct |
14 |
Correct |
18 ms |
4340 KB |
Output is correct |
15 |
Correct |
57 ms |
5088 KB |
Output is correct |
16 |
Correct |
164 ms |
5912 KB |
Output is correct |
17 |
Correct |
203 ms |
6968 KB |
Output is correct |
18 |
Correct |
1158 ms |
8324 KB |
Output is correct |
19 |
Execution timed out |
1573 ms |
3772 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1570 ms |
3576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1572 ms |
3660 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |