#include<bits/stdc++.h>
#define int long long
#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];
vector<int>a[N];
vector<int>res[N];
bool k[N];
void bfs(int u){
for(int i=0;i<n;++i)dist[i]=1e18;
dist[u]=0;
priority_queue<ii,vector<ii>,greater<ii>>p;
p.push({dist[u],u});
while(!p.empty()){
u=p.top().se;
int w=p.top().fi;
p.pop();
if(dist[u]<w)continue;
for(int nhay:a[u]){
for(int i=1;i<=n;++i){
int v=nhay*i+u;
if(v>n-1)break;
if(dist[v]>dist[u]+i){
dist[v]=dist[u]+i;
p.push({dist[v],v});
}
}
}
for(int nhay:a[u]){
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});
}
}
}
}
}
void solve(){
cin >> n >> m;
for(int i=1;i<=m;++i){
int u,v;
cin >> u >> v;
if(i==1)s=u;
if(i==2)t=u;
a[u].emb(v);
}
bfs(s);
// for(int i=0;i<=n-1;++i)cout<<dist[i]<<" ";
if(dist[t]==1e18)dist[t]=-1;
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
skyscraper.cpp:78:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
78 | main()
| ^~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:85:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:86:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
49744 KB |
Output is correct |
2 |
Correct |
9 ms |
49488 KB |
Output is correct |
3 |
Correct |
10 ms |
49488 KB |
Output is correct |
4 |
Correct |
9 ms |
49488 KB |
Output is correct |
5 |
Correct |
9 ms |
49488 KB |
Output is correct |
6 |
Correct |
10 ms |
49488 KB |
Output is correct |
7 |
Correct |
12 ms |
49488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
49488 KB |
Output is correct |
2 |
Correct |
9 ms |
49632 KB |
Output is correct |
3 |
Correct |
10 ms |
49488 KB |
Output is correct |
4 |
Correct |
9 ms |
49676 KB |
Output is correct |
5 |
Correct |
10 ms |
49632 KB |
Output is correct |
6 |
Correct |
11 ms |
49488 KB |
Output is correct |
7 |
Correct |
10 ms |
49488 KB |
Output is correct |
8 |
Correct |
8 ms |
49488 KB |
Output is correct |
9 |
Correct |
9 ms |
49488 KB |
Output is correct |
10 |
Correct |
10 ms |
49736 KB |
Output is correct |
11 |
Correct |
10 ms |
49744 KB |
Output is correct |
12 |
Correct |
11 ms |
49916 KB |
Output is correct |
13 |
Correct |
13 ms |
49744 KB |
Output is correct |
14 |
Correct |
11 ms |
49744 KB |
Output is correct |
15 |
Correct |
9 ms |
49916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
49488 KB |
Output is correct |
2 |
Correct |
10 ms |
49684 KB |
Output is correct |
3 |
Correct |
12 ms |
49488 KB |
Output is correct |
4 |
Correct |
13 ms |
49488 KB |
Output is correct |
5 |
Correct |
12 ms |
49488 KB |
Output is correct |
6 |
Correct |
14 ms |
49488 KB |
Output is correct |
7 |
Correct |
13 ms |
49488 KB |
Output is correct |
8 |
Correct |
13 ms |
49488 KB |
Output is correct |
9 |
Correct |
12 ms |
49684 KB |
Output is correct |
10 |
Correct |
9 ms |
49488 KB |
Output is correct |
11 |
Correct |
10 ms |
49744 KB |
Output is correct |
12 |
Correct |
11 ms |
49744 KB |
Output is correct |
13 |
Correct |
11 ms |
49744 KB |
Output is correct |
14 |
Correct |
12 ms |
49744 KB |
Output is correct |
15 |
Correct |
15 ms |
49744 KB |
Output is correct |
16 |
Correct |
13 ms |
49744 KB |
Output is correct |
17 |
Correct |
14 ms |
49744 KB |
Output is correct |
18 |
Correct |
13 ms |
49644 KB |
Output is correct |
19 |
Correct |
13 ms |
49744 KB |
Output is correct |
20 |
Correct |
17 ms |
49608 KB |
Output is correct |
21 |
Correct |
13 ms |
49740 KB |
Output is correct |
22 |
Correct |
18 ms |
49744 KB |
Output is correct |
23 |
Correct |
15 ms |
49744 KB |
Output is correct |
24 |
Correct |
12 ms |
49744 KB |
Output is correct |
25 |
Correct |
12 ms |
49672 KB |
Output is correct |
26 |
Correct |
18 ms |
49744 KB |
Output is correct |
27 |
Correct |
17 ms |
49744 KB |
Output is correct |
28 |
Correct |
13 ms |
49744 KB |
Output is correct |
29 |
Correct |
11 ms |
50000 KB |
Output is correct |
30 |
Correct |
12 ms |
49744 KB |
Output is correct |
31 |
Correct |
16 ms |
49792 KB |
Output is correct |
32 |
Correct |
13 ms |
49744 KB |
Output is correct |
33 |
Correct |
12 ms |
50000 KB |
Output is correct |
34 |
Correct |
11 ms |
50000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
49488 KB |
Output is correct |
2 |
Correct |
12 ms |
49488 KB |
Output is correct |
3 |
Correct |
11 ms |
49500 KB |
Output is correct |
4 |
Correct |
14 ms |
49488 KB |
Output is correct |
5 |
Correct |
16 ms |
49488 KB |
Output is correct |
6 |
Correct |
16 ms |
49628 KB |
Output is correct |
7 |
Correct |
18 ms |
49488 KB |
Output is correct |
8 |
Correct |
16 ms |
49488 KB |
Output is correct |
9 |
Correct |
15 ms |
49496 KB |
Output is correct |
10 |
Correct |
14 ms |
49488 KB |
Output is correct |
11 |
Correct |
13 ms |
49768 KB |
Output is correct |
12 |
Correct |
16 ms |
49744 KB |
Output is correct |
13 |
Correct |
13 ms |
49744 KB |
Output is correct |
14 |
Correct |
13 ms |
49916 KB |
Output is correct |
15 |
Correct |
9 ms |
49744 KB |
Output is correct |
16 |
Correct |
16 ms |
49500 KB |
Output is correct |
17 |
Correct |
13 ms |
49744 KB |
Output is correct |
18 |
Correct |
13 ms |
49744 KB |
Output is correct |
19 |
Correct |
12 ms |
49744 KB |
Output is correct |
20 |
Correct |
18 ms |
49744 KB |
Output is correct |
21 |
Correct |
13 ms |
49744 KB |
Output is correct |
22 |
Correct |
17 ms |
49488 KB |
Output is correct |
23 |
Correct |
17 ms |
49744 KB |
Output is correct |
24 |
Correct |
20 ms |
49744 KB |
Output is correct |
25 |
Correct |
15 ms |
49744 KB |
Output is correct |
26 |
Correct |
16 ms |
49744 KB |
Output is correct |
27 |
Correct |
16 ms |
49744 KB |
Output is correct |
28 |
Correct |
15 ms |
49744 KB |
Output is correct |
29 |
Correct |
13 ms |
50000 KB |
Output is correct |
30 |
Correct |
14 ms |
49744 KB |
Output is correct |
31 |
Correct |
15 ms |
49840 KB |
Output is correct |
32 |
Correct |
16 ms |
49744 KB |
Output is correct |
33 |
Correct |
17 ms |
50000 KB |
Output is correct |
34 |
Correct |
17 ms |
50140 KB |
Output is correct |
35 |
Correct |
20 ms |
50000 KB |
Output is correct |
36 |
Correct |
10 ms |
49744 KB |
Output is correct |
37 |
Correct |
13 ms |
50168 KB |
Output is correct |
38 |
Correct |
16 ms |
50428 KB |
Output is correct |
39 |
Correct |
14 ms |
50256 KB |
Output is correct |
40 |
Correct |
15 ms |
50256 KB |
Output is correct |
41 |
Correct |
16 ms |
50256 KB |
Output is correct |
42 |
Correct |
67 ms |
50000 KB |
Output is correct |
43 |
Correct |
66 ms |
50000 KB |
Output is correct |
44 |
Correct |
71 ms |
50000 KB |
Output is correct |
45 |
Correct |
15 ms |
50512 KB |
Output is correct |
46 |
Correct |
17 ms |
50512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
49680 KB |
Output is correct |
2 |
Correct |
15 ms |
49604 KB |
Output is correct |
3 |
Correct |
17 ms |
49488 KB |
Output is correct |
4 |
Correct |
21 ms |
49568 KB |
Output is correct |
5 |
Correct |
17 ms |
49488 KB |
Output is correct |
6 |
Correct |
16 ms |
49488 KB |
Output is correct |
7 |
Correct |
14 ms |
49704 KB |
Output is correct |
8 |
Correct |
14 ms |
49488 KB |
Output is correct |
9 |
Correct |
13 ms |
49488 KB |
Output is correct |
10 |
Correct |
13 ms |
49744 KB |
Output is correct |
11 |
Correct |
13 ms |
49744 KB |
Output is correct |
12 |
Correct |
10 ms |
49760 KB |
Output is correct |
13 |
Correct |
14 ms |
49744 KB |
Output is correct |
14 |
Correct |
19 ms |
49744 KB |
Output is correct |
15 |
Correct |
13 ms |
49744 KB |
Output is correct |
16 |
Correct |
15 ms |
49488 KB |
Output is correct |
17 |
Correct |
14 ms |
49744 KB |
Output is correct |
18 |
Correct |
16 ms |
49744 KB |
Output is correct |
19 |
Correct |
12 ms |
49744 KB |
Output is correct |
20 |
Correct |
18 ms |
49744 KB |
Output is correct |
21 |
Correct |
13 ms |
49744 KB |
Output is correct |
22 |
Correct |
15 ms |
49488 KB |
Output is correct |
23 |
Correct |
11 ms |
49756 KB |
Output is correct |
24 |
Correct |
14 ms |
49744 KB |
Output is correct |
25 |
Correct |
13 ms |
49744 KB |
Output is correct |
26 |
Correct |
13 ms |
49744 KB |
Output is correct |
27 |
Correct |
13 ms |
49680 KB |
Output is correct |
28 |
Correct |
10 ms |
49744 KB |
Output is correct |
29 |
Correct |
11 ms |
50000 KB |
Output is correct |
30 |
Correct |
11 ms |
49804 KB |
Output is correct |
31 |
Correct |
12 ms |
49744 KB |
Output is correct |
32 |
Correct |
11 ms |
49880 KB |
Output is correct |
33 |
Correct |
13 ms |
50000 KB |
Output is correct |
34 |
Correct |
15 ms |
50008 KB |
Output is correct |
35 |
Correct |
14 ms |
50000 KB |
Output is correct |
36 |
Correct |
17 ms |
49744 KB |
Output is correct |
37 |
Correct |
16 ms |
50256 KB |
Output is correct |
38 |
Correct |
18 ms |
50300 KB |
Output is correct |
39 |
Correct |
22 ms |
50256 KB |
Output is correct |
40 |
Correct |
20 ms |
50256 KB |
Output is correct |
41 |
Correct |
18 ms |
50256 KB |
Output is correct |
42 |
Correct |
80 ms |
50000 KB |
Output is correct |
43 |
Correct |
61 ms |
50000 KB |
Output is correct |
44 |
Correct |
74 ms |
50000 KB |
Output is correct |
45 |
Correct |
16 ms |
50512 KB |
Output is correct |
46 |
Correct |
15 ms |
50512 KB |
Output is correct |
47 |
Correct |
24 ms |
51312 KB |
Output is correct |
48 |
Correct |
19 ms |
50168 KB |
Output is correct |
49 |
Correct |
21 ms |
50164 KB |
Output is correct |
50 |
Correct |
20 ms |
50000 KB |
Output is correct |
51 |
Correct |
36 ms |
52420 KB |
Output is correct |
52 |
Correct |
34 ms |
51432 KB |
Output is correct |
53 |
Correct |
26 ms |
51404 KB |
Output is correct |
54 |
Correct |
19 ms |
50000 KB |
Output is correct |
55 |
Correct |
18 ms |
50000 KB |
Output is correct |
56 |
Correct |
652 ms |
51152 KB |
Output is correct |
57 |
Correct |
58 ms |
53844 KB |
Output is correct |
58 |
Correct |
466 ms |
50256 KB |
Output is correct |
59 |
Correct |
791 ms |
50252 KB |
Output is correct |
60 |
Correct |
550 ms |
50256 KB |
Output is correct |
61 |
Correct |
629 ms |
50252 KB |
Output is correct |
62 |
Correct |
17 ms |
50512 KB |
Output is correct |
63 |
Correct |
36 ms |
52164 KB |
Output is correct |
64 |
Correct |
39 ms |
54208 KB |
Output is correct |
65 |
Correct |
43 ms |
54208 KB |
Output is correct |
66 |
Correct |
55 ms |
54212 KB |
Output is correct |
67 |
Correct |
59 ms |
54472 KB |
Output is correct |