제출 #746015

#제출 시각아이디문제언어결과실행 시간메모리
746015vjudge1Event Hopping (BOI22_events)C++17
0 / 100
1559 ms4052 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long int; const ll mod = 1e9 + 7; int c[100100], hely[100100]; struct P { int poz, id; bool veg; }; bool cmp(P& lhs, P& rhs){ if(lhs.poz != rhs.poz){ return lhs.poz < rhs.poz; } return lhs.veg < rhs.veg; } int kov[100100] = {0}, be[100100] = {0}; vector<int> g[100100]; int main(){ int n, q; cin >> n >> q; vector<pair<int,int>> v(n + 1); for(int i = 1; i <= n; ++i){ cin >> v[i].first >> v[i].second; } for(int i = 1; i <= n; ++i){ for(int j = 1; j <= n; ++j){ if(i == j) continue; if(v[j].first <= v[i].second && v[i].second < v[j].second){ g[i].push_back(j); cerr << "el: " << i << " " << j << endl; ++be[j]; } } } vector<int> topsort = {0}; queue<int> s; for(int i = 1; i <= n; ++i){ if(be[i] == 0){ s.push(i); } } while(!s.empty()){ auto p = s.front(); s.pop(); topsort.push_back(p); for(auto i : g[p]){ --be[i]; if(be[i] == 0) s.push(i); } } vector<int> poz(n + 1); for(int i = 1; i <= n; ++i){ cerr << topsort[i] << endl; poz[topsort[i]] = i; } while(q--){ int a, b; cin >> a >> b; vector<int> dp(n + 1, 1e9); dp[poz[a]] = 0; for(int i = poz[a]; i <= n; ++i){ for(auto j : g[topsort[i]]){ dp[poz[j]] = min(dp[poz[j]], dp[i] + 1); } } if(dp[poz[b]] == 1e9){ cout << "impossible" << endl; } else{ cout << dp[poz[b]] << endl; } } 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...