#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
int t, n;
vi a, b;
vector<vi> adj;
int ans[5500][5500];
int vis[5500][5500];
int main(){
int q;
cin>>n>>q;
adj.assign(n+1, vi());
vii e(n);
FOR(i,n){
cin>>e[i].F>>e[i].S;
}
FOR(i,n){
FOR(j,n){
if(i==j) continue;
if(e[j].F<=e[i].S && e[i].S<=e[j].S){
adj[i+1].push_back(j+1);
}
}
/*
cout<<i+1<<": ";
FOA(v, adj[i+1]) cout<<v<<" ";
cout<<endl;
*/
}
FORi(i,1,n+1){
queue<ii> q;
q.push({0, i});
FOR(j,n+1) ans[i][j] = MOD, vis[i][j] = 0;
ans[i][i] = 0;
while(!q.empty()){
ii t = q.front();
q.pop();
if(vis[i][t.S]) continue;
FOA(v, adj[t.S]){
if(ans[i][v] > 1 - t.F){
ans[i][v] = 1 - t.F;
q.push({-ans[i][v], v});
}
}
vis[i][t.S] = true;
}
}
while(q--){
int a, b;
cin>>a>>b;
if(ans[a][b] < MOD) cout<<ans[a][b]<<endl;
else cout<<"impossible\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
1543 ms |
4416 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
26 ms |
16268 KB |
Output is correct |
4 |
Correct |
20 ms |
16280 KB |
Output is correct |
5 |
Correct |
26 ms |
16196 KB |
Output is correct |
6 |
Correct |
55 ms |
17004 KB |
Output is correct |
7 |
Correct |
129 ms |
17868 KB |
Output is correct |
8 |
Correct |
159 ms |
18908 KB |
Output is correct |
9 |
Correct |
803 ms |
20308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
26 ms |
16268 KB |
Output is correct |
4 |
Correct |
20 ms |
16280 KB |
Output is correct |
5 |
Correct |
26 ms |
16196 KB |
Output is correct |
6 |
Correct |
55 ms |
17004 KB |
Output is correct |
7 |
Correct |
129 ms |
17868 KB |
Output is correct |
8 |
Correct |
159 ms |
18908 KB |
Output is correct |
9 |
Correct |
803 ms |
20308 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
28 ms |
16188 KB |
Output is correct |
13 |
Correct |
18 ms |
16228 KB |
Output is correct |
14 |
Correct |
25 ms |
16244 KB |
Output is correct |
15 |
Correct |
50 ms |
16972 KB |
Output is correct |
16 |
Correct |
129 ms |
17812 KB |
Output is correct |
17 |
Correct |
157 ms |
18888 KB |
Output is correct |
18 |
Correct |
777 ms |
20224 KB |
Output is correct |
19 |
Execution timed out |
1578 ms |
52480 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
26 ms |
16268 KB |
Output is correct |
4 |
Correct |
20 ms |
16280 KB |
Output is correct |
5 |
Correct |
26 ms |
16196 KB |
Output is correct |
6 |
Correct |
55 ms |
17004 KB |
Output is correct |
7 |
Correct |
129 ms |
17868 KB |
Output is correct |
8 |
Correct |
159 ms |
18908 KB |
Output is correct |
9 |
Correct |
803 ms |
20308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
25 ms |
16244 KB |
Output is correct |
13 |
Correct |
17 ms |
16168 KB |
Output is correct |
14 |
Correct |
25 ms |
16196 KB |
Output is correct |
15 |
Correct |
52 ms |
17016 KB |
Output is correct |
16 |
Correct |
134 ms |
17776 KB |
Output is correct |
17 |
Correct |
178 ms |
18872 KB |
Output is correct |
18 |
Correct |
821 ms |
20280 KB |
Output is correct |
19 |
Execution timed out |
1576 ms |
4816 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1550 ms |
4664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
1543 ms |
4416 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |