# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
604350 | Plurm | Event Hopping (BOI22_events) | C++11 | 1595 ms | 81488 KiB |
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 <bits/stdc++.h>
using namespace std;
vector<int> g[100005];
short dist[5005][5005];
int main() {
memset(dist, 0x3F, sizeof(dist));
int n, q;
scanf("%d%d", &n, &q);
vector<pair<int, int>> events;
int k = sqrt(n);
for (int i = 1; i <= n; i++) {
int s, e;
scanf("%d%d", &s, &e);
events.push_back({s, e});
}
for (int i = 0; i < n; i++) {
vector<int> tmp;
for (int j = 0; j < n; j++) {
if (i == j)
continue;
if (events[j].first <= events[i].second &&
events[i].second <= events[j].second) {
g[i].push_back(j);
}
}
}
queue<int> pq;
for (int i = 0; i < n; i++) {
dist[i][i] = 0;
pq.push(i);
while (!pq.empty()) {
int u = pq.front();
pq.pop();
for (int v : g[u]) {
if (dist[i][v] > dist[i][u] + 1) {
dist[i][v] = dist[i][u] + 1;
pq.push(v);
}
}
}
}
for (int i = 0; i < q; i++) {
int s, e;
scanf("%d%d", &s, &e);
if (dist[s - 1][e - 1] > n)
printf("impossible\n");
else
printf("%hd\n", dist[s - 1][e - 1]);
// can e be reached by s?, if yes, what is the shortest path?
}
return 0;
}
Compilation message (stderr)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |