Submission #1050570

#TimeUsernameProblemLanguageResultExecution timeMemory
1050570VMaksimoski008Event Hopping (BOI22_events)C++17
10 / 100
121 ms3288 KiB
#include <bits/stdc++.h> //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; signed main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); int n, q; cin >> n >> q; vector<pii> v(n+1); for(int i=1; i<=n; i++) cin >> v[i].first >> v[i].second; if(n <= 1000 && q <= 100) { while(q--) { int s, t; cin >> s >> t; vector<int> dist(n+1, -1); queue<int> q; q.push(s); dist[s] = 0; while(!q.empty()) { int u = q.front(); q.pop(); for(int i=1; i<=n; i++) { if(dist[i] != -1) continue; if(v[i].first <= v[u].second && v[u].second <= v[i].second) { dist[i] = dist[u] + 1; q.push(i); } } } if(dist[t] == -1) cout << "impossible\n"; else cout << dist[t] << '\n'; } return 0; } return 0; }
#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...