QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#209929 | #4206. Event Hopping | HossamHero7# | 0 | 276ms | 14144kb | C++14 | 1.4kb | 2023-10-10 19:48:59 | 2024-07-04 02:18:15 |
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;
array<int,2> 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][0]<=v[i][1]&&v[i][1]<=v[j][1]) add(i,j);
}
}
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;
}
詳細信息
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: 276ms
memory: 14144kb
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%