Submission #646019

# Submission time Handle Problem Language Result Execution time Memory
646019 2022-09-28T13:53:38 Z GaLz Event Hopping (BOI22_events) C++14
0 / 100
23 ms 5612 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;
const ll maxn=1e5+5;
const int INF=1e8;
#define ok ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define endl '\n'
vi adj[maxn];
int n, q, dis[5001][5001], u, v;
pii arr[maxn];
void dfs(int st, int now) {
    for(auto it : adj[now]) {
        if(!dis[st][it]) {
            dis[st][it]=dis[st][now]+1;
            dfs(st, it);
        }
    }
}
int main() {
    ok
    cin >> n >> q;
    for(int i=1; i<=n; i++) cin >> arr[i].fi >> arr[i].se;
    if(n<=5000) {
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=n; j++) {
                if(i==j) continue;
                if(arr[i].se>=arr[j].fi && arr[i].se<=arr[j].se) adj[i].pb(j);
            }
        }
        for(int i=1; i<=n; i++) {
            dfs(i, i);
        }
        while(q--) {
            cin >> u >> v;
            if(u==v) cout << 0;
            else if(dis[u][v]) cout << dis[u][v];
            else cout << "impossible";
            cout << endl;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 23 ms 5612 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 5592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 23 ms 5612 KB Output isn't correct
3 Halted 0 ms 0 KB -