# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
888765 | vjudge1 | Passport (JOI23_passport) | C++17 | 2086 ms | 6616 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
int pow(int a,int b,int m){int ans=1;while(b){if(b&1){ans=(ans*a)%m;}b>>=1;a=(a*a)%m;}return ans;}
int binpow(int a,int b){int ans=1;while(b){if(b&1){ans=(ans*a);}b>>=1;a=(a*a);}return ans;}
const int N = 2e5 + 10;
int dist[N];
main(){
ios :: sync_with_stdio(0);
cin.tie(0);
// memset(dist, 0x3f3f, sizeof(dist));
int n;
cin >> n;
vector <pair <int,int> > vp(n + 1);
for(int i = 1; i <= n; i++){
cin >> vp[i].ff >> vp[i].ss;
}
int just;
cin >> just;
while(just--){
for(int i = 1; i <= n; i++)dist[i] = 1e18;
int pos;
cin >> pos;
queue<int> q;
q.push(pos);
dist[pos] = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int i = vp[v].ff; i <= vp[v].ss; i++) {
int to = i;
if(dist[to] > dist[v] + 1){
dist[to] = dist[v] + 1;
q.push(to);
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
ans = max(dist[i], ans);
}
if(n == 1)
ans = 1;
else if(ans == 1e18)
cout << "-1\n";
else
cout <<ans << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |