# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
604344 | Plurm | Event Hopping (BOI22_events) | C++11 | 1591 ms | 101784 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> g[100005];
int dist[5005][5005];
int main() {
memset(dist, 0x3F, sizeof(dist));
int n, q;
scanf("%d%d", &n, &q);
vector<pair<int, int>> events;
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++) {
int mx = -1;
int midx = -1;
for (int j = 0; j < n; j++) {
if (i == j)
continue;
if (events[j].first <= events[i].second &&
events[i].second <= events[j].second) {
if (events[j].second > mx) {
mx = events[j].second;
midx = j;
}
}
}
if (midx != -1)
g[i].push_back(midx);
}
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] > 1e9)
printf("impossible\n");
else
printf("%d\n", dist[s - 1][e - 1]);
// can e be reached by s?, if yes, what is the shortest path?
}
return 0;
}
컴파일 시 표준 에러 (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... |