Submission #679548

#TimeUsernameProblemLanguageResultExecution timeMemory
679548penguin133Event Hopping (BOI22_events)C++17
10 / 100
1586 ms136840 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif vector<int> lmao[100005]; int S[100005], E[100005], dist[100005]; int n, q; void solve(){ cin >> n >> q; for(int i=1;i<=n;i++)cin >> S[i] >> E[i]; set <pi> st; for(int i=1;i<=n;i++)st.insert({E[i], i}); for(int i=1;i<=n;i++){ set<pi> :: iterator it = st.lower_bound({S[i], 0}); while(it != st.end()){ pi tmp = *it; if(tmp.fi > E[i])break; lmao[tmp.se].push_back(i); it++; } } while(q--){ int x, y; cin >> x >> y; queue<int>qu; for(int i=1;i<=n;i++)dist[i] = 1e9; dist[x] = 0; qu.push(x); while(!qu.empty()){ int a = qu.front(); qu.pop(); for(auto i : lmao[a]){ if(dist[i] > dist[a] + 1)dist[i] = dist[a] + 1, qu.push(i); } } if(dist[y] != 1e9)cout << dist[y] << '\n'; else cout << "impossible\n"; } } main(){ ios::sync_with_stdio(0);cin.tie(0); int tc = 1; //cin >> tc; for(int tc1=1;tc1<=tc;tc1++){ // cout << "Case #" << tc1 << ": "; solve(); } }

Compilation message (stderr)

events.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main(){
      | ^~~~
#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...