Submission #714273

# Submission time Handle Problem Language Result Execution time Memory
714273 2023-03-24T07:41:49 Z vjudge1 Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 3952 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<bool> visited;
int dfs(int node, int target){
    if(node == target) return 0;
    visited[node] = 1;
    int ans = oo;
    for(int to:g[node]){
        if(visited[to]) continue;
        ans = min(ans, dfs(to, target) + 1);
    }
    visited[node] = 0;
    return ans;
}

int main(){
    int n, q; cin >> n >> q;
    visited.resize(n + 1, 0);
    vector<pii> v(n + 1);
    g.resize(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> v[i].first >> v[i].second;
    }
    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--){
        int u, v; cin >> u >> v;
        int ans = dfs(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 1547 ms 3952 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 352 KB Output is correct
4 Correct 6 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Execution timed out 1575 ms 1108 KB Time limit exceeded
7 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 352 KB Output is correct
4 Correct 6 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Execution timed out 1575 ms 1108 KB Time limit exceeded
7 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 352 KB Output is correct
4 Correct 6 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Execution timed out 1575 ms 1108 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1540 ms 3608 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 1547 ms 3952 KB Time limit exceeded
3 Halted 0 ms 0 KB -