# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
595547 | ThegeekKnight16 | Event Hopping (BOI22_events) | C++14 | 1584 ms | 32716 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;
const int MAXN = 1e5 + 10;
int Inicio[MAXN], Fim[MAXN];
vector<int> Indices;
vector<int> grafo[MAXN];
int Marc[MAXN], Dist[MAXN];
void bfs(int v, int N)
{
for (int i = 1; i <= N; i++) {Marc[i] = 0; Dist[i] = 1e9 + 10;}
queue<int> q;
Marc[v] = 1; Dist[v] = 0;
q.push(v);
while (!q.empty())
{
int cur = q.front(); q.pop();
for (auto viz : grafo[cur])
{
if (Marc[viz]) continue;
Dist[viz] = Dist[cur] + 1;
Marc[viz] = 1;
q.push(viz);
}
}
}
bool cmp(int a, int b)
{
if (Fim[a] == Fim[b]) return Inicio[a] < Inicio[b];
return Fim[a] > Fim[b];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, Q;
cin >> N >> Q;
for (int i = 1; i <= N; i++)
{
cin >> Inicio[i] >> Fim[i];
Indices.push_back(i);
}
sort(Indices.begin(), Indices.end(), cmp);
for (int i = 0; i < Indices.size(); i++)
{
int id = Indices[i];
for (int j = 0; j < Indices.size(); j++)
{
int jd = Indices[j];
if (Inicio[jd] <= Fim[id] && Fim[id] <= Fim[jd]) {grafo[id].push_back(jd);}
}
}
for (int q = 1; q <= Q; q++)
{
int X, Y;
cin >> X >> Y;
bfs(X, N);
if (Dist[Y] == 1e9 + 10) cout << "impossible" << '\n';
else cout << Dist[Y] << '\n';
}
}
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... |