제출 #1315993

#제출 시각아이디문제언어결과실행 시간메모리
1315993vlomaczkEvent Hopping (BOI22_events)C++20
0 / 100
1595 ms589824 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; ll inf = 1e9; vector<vector<int>> ans(n, vector<int>(n, inf)), g(n, vector<int>()); // vector<vector<int>> par(n, vector<int>(n, inf)); vector<pair<int, int>> seg(n); for(int i=0; i<n; ++i) cin >> seg[i].first >> seg[i].second; for(int v=0; v<n; ++v) { for(int j=0; j<n; ++j) { if(seg[j].first <= seg[v].second && seg[v].second <= seg[j].second) { g[v].push_back(j); } } } queue<int> Q; for(int s=0; s<n; ++s) { ans[s][s] = 0; Q.push(s); while(Q.size()) { int v = Q.front(); Q.pop(); for(int j=0; j<n; ++j) { for(auto j : g[v]) { if(ans[s][j] == inf) { ans[s][j] = ans[s][v] + 1; // par[s][j] = v; Q.push(j); } } } } } while(q--) { int a, b; cin >> a >> b; --a;--b; if(ans[a][b]==inf) cout << "impossible\n"; else cout << ans[a][b] << "\n"; /*int v = b; while(v!=inf) { cout << v << " <- "; v = par[a][v]; } cout << "\n";*/ } 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...