Submission #573006

#TimeUsernameProblemLanguageResultExecution timeMemory
573006AmirElarbiEvent Hopping (BOI22_events)C++14
10 / 100
176 ms4428 KiB
#include <bits/stdc++.h> #define vi vector<int> #define ve vector #define ll long long #define vf vector<float> #define vll vector<pair<ll,ll>> #define ii pair<int,int> #define vvi vector<vi> #define vii vector<ii> #define gii greater<ii> #define pb push_back #define mp make_pair #define fi first #define se second #define INF 1e9 #define eps 1e-7 #define eps1 1e-2 #define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define MAX_A 2e5+5 using namespace std; const int MOD = 1e4+7; const int nax = 1005; const int nax2 = 200005; typedef complex<int> Point; #define X real() #define Y imag() int s[nax],e[nax]; vi adj[nax]; vi d; int main(){ optimise; int n,q; cin >> n >> q; for (int i = 0; i < n; ++i) { cin >> s[i] >> e[i]; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if(i==j) continue; if(e[i] <= e[j] && s[j] <= e[i]) adj[i].pb(j); } } while(q--){ int s,e; cin >> s >> e; s--,e--; int res = -1; if(s == e) { cout << 0 << endl; continue; } d.assign(n, INF); d[s] = 0; set<ii> q; q.insert({0, s}); while (!q.empty()) { int v = q.begin()->second; q.erase(q.begin()); for (auto edge : adj[v]) { int u = edge; if (d[v] + 1 < d[u]) { q.erase({d[u], u}); d[u] = d[v] + 1; if(u == e) { res = d[u]; break; } q.insert({d[u], u}); } } } if(res == -1) cout << "impossible" << endl; else cout << res << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...