Submission #971968

# Submission time Handle Problem Language Result Execution time Memory
971968 2024-04-29T15:32:10 Z idas Event Hopping (BOI22_events) C++11
0 / 100
5 ms 2396 KB
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define sz(x) int((x).size())
#define pb push_back
#define s second
#define f first

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;

const int INF=1e9;

const int N=5010;
int n, q, s[N], e[N], d[N][N];
vi ad[N];

int main()
{
    FAST_IO;
    cin >> n >> q;
    FOR(i, 0, n)
    {
        cin >> s[i] >> e[i];
    }

    FOR(i, 0, n)
    {
        FOR(j, 0, n)
        {
            if(i==j) continue;
            if(s[j]<=e[i] && e[i]<e[j]){
                ad[i].pb(j);
//                cout << i << " -> " << j << '\n';
            }
        }
    }

    FOR(i, 0, n) FOR(j, 0, n) if(i!=j) d[i][j]=-1;

    FOR(i, 0, n)
    {
        queue<int> q; q.push(i);
        while(!q.empty()){
            int u=q.front(); q.pop();
            for(auto x : ad[u]){
                if(d[i][x]==-1){
                    d[i][x]=d[i][u]+1;
                    q.push(x);
                }
            }
        }
    }

    while(q--){
        int a, b; cin >> a >> b; --a; --b;
        if(d[a][b]==-1){
            cout << "impossible\n";
        }
        else{
            cout << d[a][b] << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 800 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -