# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
888713 | vjudge1 | Passport (JOI23_passport) | C++17 | 1 ms | 348 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 all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);
int n;
cin>>n;
vector <int> l(n),r(n);
for(int i=0;i<n;i++)cin>>l[i]>>r[i];
vector <int> a,b,c;
for(int i=0;i<n;i++){
for(int j=l[i];j<=r[i];j++){
a.pb(i+1);
b.pb(j);
c.pb(1);
}
}
int q;cin>>q;
set <pair <int,int> > st;
vector <int> ans;
while(q--){
int x;cin>>x;
vector <int> d(n+1,1e9),p(n+1);
d[x]=0;
for(int i=0;i<n;i++){
for(int j=0;j<a.size();j++){
if(d[a[j]]!=1e9 && d[b[j]]>d[a[j]]+c[j]){
d[b[j]]=d[a[j]]+c[j];
p[b[j]]=a[j];
}
}
}
int mx=0;
set <int> s;
for(int i=1;i<=n;i++){
mx=max(mx,d[i]);
if(d[i]==1e9)break;
int curv=i;
while(curv!=x){
curv=p[curv];
s.insert(curv);
}
}
if(mx==1e18)cout<<-1<<"\n";
else cout<<s.size()<<"\n";
}
}
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... |