Submission #714299

# Submission time Handle Problem Language Result Execution time Memory
714299 2023-03-24T08:13:10 Z vjudge1 Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 30432 KB
#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, int>
#define oo 1e9

using namespace std;

vector<vector<int>> g;
vector<int> visited;
int bfs(int start, int target){
    queue<pii> q;
    q.push({start, 0});
    visited[start] = true;
    while(!q.empty()){
        int node = q.front().first;
        int d = q.front().second;
        q.pop();
        if(node == target) return d;
        for(int to:g[node]){
            if(visited[to]) continue;
            q.push({to, d + 1});
            visited[to] = true;
        }
    }
    return oo;
}

int main(){
    int n, q; cin >> n >> q;
    vector<pii> v(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> v[i].first >> v[i].second;
    }
    visited.resize(n + 1, 0);
    g.resize(n + 1);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if(i == j) continue;
            if(v[i].second <= v[j].second && v[i].second >= v[j].first){
                g[i].emplace_back(j);
            }
        }
    }
    
    while(q--){
        fill(visited.begin(), visited.end(), 0);
        int u, v; cin >> u >> v;
        int ans = bfs(u, v);
        if(ans == oo){
            cout << "impossible\n";
        }
        else{
            cout << ans << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1580 ms 4004 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 7 ms 340 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Correct 11 ms 1108 KB Output is correct
7 Correct 22 ms 1876 KB Output is correct
8 Correct 18 ms 2900 KB Output is correct
9 Correct 43 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 7 ms 340 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Correct 11 ms 1108 KB Output is correct
7 Correct 22 ms 1876 KB Output is correct
8 Correct 18 ms 2900 KB Output is correct
9 Correct 43 ms 4308 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 340 KB Output is correct
13 Correct 6 ms 352 KB Output is correct
14 Correct 6 ms 340 KB Output is correct
15 Correct 10 ms 1108 KB Output is correct
16 Correct 18 ms 1876 KB Output is correct
17 Correct 22 ms 2900 KB Output is correct
18 Correct 52 ms 4308 KB Output is correct
19 Execution timed out 1588 ms 30432 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 7 ms 340 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Correct 11 ms 1108 KB Output is correct
7 Correct 22 ms 1876 KB Output is correct
8 Correct 18 ms 2900 KB Output is correct
9 Correct 43 ms 4308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 340 KB Output is correct
13 Correct 8 ms 340 KB Output is correct
14 Correct 6 ms 340 KB Output is correct
15 Correct 10 ms 1032 KB Output is correct
16 Correct 17 ms 1960 KB Output is correct
17 Correct 18 ms 3004 KB Output is correct
18 Correct 60 ms 4308 KB Output is correct
19 Execution timed out 1574 ms 4004 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1568 ms 4100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1580 ms 4004 KB Time limit exceeded
3 Halted 0 ms 0 KB -