Submission #960755

#TimeUsernameProblemLanguageResultExecution timeMemory
960755Trisanu_DasEvent Hopping (BOI22_events)C++17
10 / 100
1586 ms30808 KiB
#include <bits/stdc++.h> using namespace std; #define S first #define E second int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, q; cin >> n >> q; pair<int, int> ev[n]; for(int i = 0; i < n; i++) cin >> ev[i].S >> ev[i].E; vector<int> adj[n]; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j && ev[j].S <= ev[i].E && ev[i].E <= ev[j].E) adj[i].push_back(j); while(q--){ int s, e; cin >> s >> e; s--; e--; vector<int> d(n, -1); queue<int> q; d[s] = 0; q.push(s); while(!q.empty()){ int u = q.front(); q.pop(); if(u == e) break; for(int v : adj[u]){ if(d[v] != -1) continue; d[v] = d[u] + 1; q.push(v); } } if(d[e] == -1) cout << "impossible\n"; else cout << d[e] << '\n'; } }
#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...