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 str string
#define task "strdel"
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii,ii>
#define se second
#define fi first
#define ffi fi.fi
#define sfi se.fi
#define sse se.se
#define fse fi.se
#define lt(i, c, d) for(int i = c; i <= d; ++i)
#define fl(i, c, d) for(int i = d; i >= c; --i)
#define pb push_back
#define emb emplace_back
#define em emplace
using namespace std;
const int N=1e6+5,lg=20,mod=1e9+7;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int u,int v){
return u+rd()%(v-u+1);
}
int n,m,s,t,ans,dist[N];
ii a[N];
vector<int>res[N];
bool k[N];
void bfs(int u){
for(int i=0;i<n;++i)dist[i]=1e9;
dist[u]=0;
priority_queue<iii,vector<iii>,greater<iii>>p;
p.push({0,{a[1].fi,a[1].se}});
while(!p.empty()){
int u=p.top().sfi;
int nhay=p.top().sse;
int w=p.top().fi;
p.pop();
for(int i=1;i<=n;++i){
int v=u+nhay*i;
if(v>n-1)break;
if(dist[v]>dist[u]+i){
dist[v]=dist[u]+i;
p.push({dist[v],{v,nhay}});
if(!k[v]){
for(int i:res[v])p.push({dist[v],{v,a[i].se}});
}
}
}
for(int i=1;i<=n;++i){
int v=u-nhay*i;
if(v<0)break;
if(dist[v]>dist[u]+i){
dist[v]=dist[u]+i;
p.push({dist[v],{v,nhay}});
if(!k[v]){
for(int i:res[v])p.push({dist[v],{v,a[i].se}});
}
}
}
}
}
void solve(){
cin >> n >> m;
for(int i=1;i<=m;++i){
cin >> a[i].fi >> a[i].se;
if(i==1)s=a[i].fi;
else if(i==2)t=a[i].fi;
else res[a[i].fi].emb(i);
}
bfs(s);
// for(int i=0;i<=n-1;++i)cout<<dist[i]<<" ";
cout << dist[t];
}
main()
{
srand(time(0));
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
int t=1;
// cin >> t;
while(t--){
solve();
cout<<'\n';
}
}
Compilation message (stderr)
skyscraper.cpp: In function 'void bfs(int)':
skyscraper.cpp:37:12: warning: unused variable 'w' [-Wunused-variable]
37 | int w=p.top().fi;
| ^
skyscraper.cpp: At global scope:
skyscraper.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
76 | main()
| ^~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:83:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:84:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |