Submission #714410

#TimeUsernameProblemLanguageResultExecution timeMemory
714410Ferid20072020Event Hopping (BOI22_events)C++14
10 / 100
1592 ms399832 KiB
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define ui unsigned int #define f first #define s second #define ins insert #define pb push_back #define mp make_pair #define ln '\n' #define int ll #define pii pair<int , int> #define INF LLONG_MAX #define vv(a) vector<a> #define pp(a, b) pair<a, b> #define pq(a) priority_queue<a> #define qq(a) queue<a> #define ss(a) set<a> #define mss(a) multiset<a> #define mm(a, b) map<a, b> #define mmm(a , b) multimap<a , b> #define sz(x) (x).size() #define all(x) (x).begin() , (x).end() #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// const int MAX = 5010; vv(pii) a(MAX); vv(vv(int)) g(MAX); vv(vv(int)) dist(MAX , vv(int) (MAX , -1)); void BFS(int node){ dist[node][node] = 0; queue<int> Q; Q.push(node); while(!Q.empty()){ int from = Q.front(); Q.pop(); for(auto to : g[from]){ if(dist[node][to] == -1){ dist[node][to] = dist[node][from] + 1; Q.push(to); } } } } void solve(){ int n , q; cin >> n >> q; for(int i=0 ; i<n ; i++){ cin >> a[i].f >> a[i].s; } for(int i=0 ; i<n ; i++){ for(int j=0 ; j<n ; j++){ if(i != j){ if(a[j].f <= a[i].s && a[j].s >= a[i].s){ g[i].pb(j); } } } } for(int i=0 ; i<n ; i++){ BFS(i); } //cout << dist[0][3] << ln; for(int i=0 ; i<q ; i++){ int u , v; cin >> u >> v; u--; v--; if(dist[u][v] == -1){ cout << "impossible" << ln; } else{ cout << dist[u][v] << ln; } } } signed main(){ fastio int t = 1; //cin >> t; while(t--){ solve(); } 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...