#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } #line 1 "Graph2/GraphTemplate.cpp" // graph template // ref : https://ei1333.github.io/library/graph/graph-template.cpp template struct Edge{ int from,to; T w; int idx; Edge()=default; Edge(int from,int to,T w=1,int idx=-1):from(from),to(to),w(w),idx(idx){} operator int() const{return to;} }; template struct Graph{ vector>> g; int V,E; Graph()=default; Graph(int n):g(n),V(n),E(0){} size_t size(){ return g.size(); } void resize(int k){ g.resize(k); } inline const vector> &operator[](int k)const{ return (g.at(k)); } inline vector> &operator[](int k){ return (g.at(k)); } void add_directed_edge(int from,int to,T cost=1){ g[from].emplace_back(from,to,cost,E++); } void add_edge(int from,int to,T cost=1){ g[from].emplace_back(from,to,cost,E); g[to].emplace_back(to,from,cost,E++); } void read(int m,int pad=-1,bool weighted=false,bool directed=false){ for(int i=0;i>u>>v; u+=pad,v+=pad; T w=T(1); if(weighted) cin>>w; if(directed) add_directed_edge(u,v,w); else add_edge(u,v,w); } } }; #line 2 "Graph2/Dijkstra.cpp" template struct Dijkstra{ const T inf; Graph g; vector d; vector prev; Dijkstra(Graph g):inf(numeric_limits::max()/2),g(g){} vector build(int st){ d.assign(g.V,inf); prev.assign(g.V,-1); d[st]=0; priority_queue,vector>,greater>> que; que.emplace(d[st],st); while(!que.empty()){ auto p=que.top();que.pop(); int cur=p.second; if(d[cur]d[cur]+e.w){ d[e]=d[cur]+e.w; prev[e]=cur; que.emplace(d[e],e); } } } return d; } vector get_path(int gl){ vector ret; if(d[g]==inf) return ret; for(;gl!=-1;gl=prev[gl]) ret.push_back(gl); reverse(ret.begin(),ret.end()); return ret; } }; signed main(){ int n,k;cin>>n>>k; if(n==2){ cout<<"YES"< g(n+1); for(int i=n;i>0;i--){ if(i-3>0) g.add_directed_edge(i,i-3); if(i%2==0) g.add_directed_edge(i,i/2); } Dijkstra dij(g); auto d=dij.build(n); cout<<(d[1]