QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209931 | #4206. Event Hopping | HossamHero7# | 0 | 210ms | 12444kb | C++14 | 1.4kb | 2023-10-10 19:50:54 | 2024-07-04 02:18:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int n;
const int N = 5000, M = 12502501;
int head[N],to[M],nxt[M],ne;
void add(int a,int b){
to[ne] = b;
nxt[ne] = head[a];
head[a] = ne++;
}
vector<int> bfs(int src){
queue<int> q;
q.push(src);
vector<int> dep(n,1e9);
dep[src] = 0;
while(q.size()){
int node = q.front(); q.pop();
for(int e=head[node];~e;e=nxt[e]){
int ch = to[e];
if(dep[ch] != 1e9) continue;
q.push(ch);
dep[ch] = dep[node] + 1;
}
}
return dep;
}
void solve(){
int q;
cin>>n>>q;
pair<int,int> v[n];
for(auto &[s,e] : v) cin>>s>>e;
memset(head,-1,sizeof(head));
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i == j) continue;
if(v[j].first<=v[i].second&&v[i].second<=v[j].second) add(i,j);
}
}
vector<vector<int>> dis(n);
for(int src=0;src<n;src++) dis[src] = bfs(src);
while(q--){
int s,e;
cin>>s>>e;
int ans = dis[s-1][e-1];
if(ans == 1e9) cout<<"impossible"<<endl;
else cout<<ans<<endl;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
100000 100000 825913690 825916363 333322014 333324481 302015784 302018251 841002775 841005448 810249910 810252583 803554045 803556718 379590599 379593066 413477311 413479778 304105333 304107800 856802878 856805551 355907399 355909866 365590374 365592841 813775597 813778270 816058339 816061012 383873...
output:
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #13:
score: 10
Accepted
time: 210ms
memory: 12444kb
input:
1000 100 67878298 387720407 270457472 922959000 286470357 618323410 260791474 282940414 301337446 553875076 478221503 724555102 380447228 437131400 191801427 465825895 366088873 431222136 49483883 103442781 699926238 720636919 253150351 291688158 411085513 727726933 444078045 496386017 420626857 822...
output:
1 2 2 impossible 1 2 1 2 impossible 2 2 impossible impossible impossible 1 impossible impossible impossible impossible impossible 2 impossible 2 impossible 1 1 impossible 1 1 1 1 impossible 2 impossible 2 impossible 1 1 impossible impossible impossible 1 2 impossible impossible 1 2 impossible imposs...
result:
ok 100 lines
Test #14:
score: -10
Time Limit Exceeded
input:
1000 100 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 100...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Time Limit Exceeded
Test #35:
score: 0
Time Limit Exceeded
input:
100000 100000 903318459 905410836 903528407 905653109 925180437 927048927 473524826 475597377 362562616 364539688 644980844 646918450 242583398 244653279 506338025 508361063 481496693 483530832 970053326 972147109 794840350 796900045 130664210 132709680 634100524 636336820 844429264 846504591 652483...
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
0%