Submission #1084381

# Submission time Handle Problem Language Result Execution time Memory
1084381 2024-09-06T07:02:32 Z Bananabread Passport (JOI23_passport) C++17
0 / 100
1 ms 348 KB
#include<bits/stdc++.h>
#define ll long long
#define ntr "\n"
#define mod (ll)(1e9+7)
#define taskname ""
#define frep freopen(taskname".inp","r",stdin); freopen(taskname".out","w",stdout);
using namespace std;
vector<ll> adj[3001];
ll dist[3001];
ll vis[3001];
ll n;
ll q;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //frep;
    cin>>n;
    for(int i=1;i<=n;i++){
        ll l,r;
        cin>>l>>r;
        for(int j=l;j<=r;j++){
            adj[i].push_back(j);
        }
    }
    cin>>q;
    for(int i=1;i<=q;i++){
        ll x;
        cin>>x;
        fill(dist+1,dist+n+1,1e18);
        fill(vis+1,vis+n+1,0);
        dist[x]=1;
        queue<ll> q;
        q.push(x);
        while(!q.empty()){
            ll u=q.front();
            q.pop();
            if(vis[u]) continue;
            vis[u]=1;
            for(auto v:adj[u]){
                if(dist[v]>dist[u]+1){
                    dist[v]=dist[u]+1;
                    q.push(v);
                }
            }
        }
        ll mx=max(dist[1],dist[n]);
        if(mx==1e18) cout<<-1;
        else cout<<mx;
        cout<<ntr;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -