Submission #714293

#TimeUsernameProblemLanguageResultExecution timeMemory
714293TheSahibEvent Hopping (BOI22_events)C++14
0 / 100
1584 ms3600 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define oo 1e9 using namespace std; vector<vector<int>> g; vector<bool> visited; int dfs(int node, int target){ if(node == target) return 0; visited[node] = 1; int ans = oo; for(int to:g[node]){ if(visited[to]) continue; ans = min(ans, dfs(to, target) + 1); } visited[node] = 0; return ans; } int main(){ 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; } visited.resize(n + 1, 0); g.resize(n + 1); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if(i == j) continue; if(v[i].second <= v[j].second && v[i].second >= v[j].first){ g[i].emplace_back(j); } } } while(q--){ int u, v; cin >> u >> v; int ans = dfs(u, v); if(ans == oo){ cout << "impossible\n"; } else{ cout << ans << '\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...