-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path520B.cpp
More file actions
56 lines (46 loc) · 707 Bytes
/
520B.cpp
File metadata and controls
56 lines (46 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<bits/stdc++.h>
using namespace std;
vector<int> edge[20005];
bool vis[20005];
int dist[20005];
void bfs(int n, int m)
{
for(int i = 0; i<=20004; i++)
{
vis[i] = false;
dist[i] = 1000000;
}
vis[n] = true;
dist[n] = 0;
queue<int> q;
q.push(n);
while(!q.empty())
{
int x = q.front();
q.pop();
for(auto it = edge[x].begin(); it!=edge[x].end(); it++)
{
if(!vis[*it])
{
if(dist[*it]>1+dist[x])
dist[*it] = 1 + dist[x];
vis[*it] = true;
q.push(*it);
}
}
}
cout<<dist[m];
}
int main()
{
int n,m;
cin>>n>>m;
for(int i = 1; i<=10002; i++)
{
edge[i].push_back(2*i);
if(i>1)
edge[i].push_back(i-1);
}
bfs(n,m);
return 0;
}