#include<bits/stdc++.h>
using namespace std;
#define int long long
const int n=1e4;
vector<pair<int,int>>t[n];
int a,b,c,dis[n];
struct s
{
int x,y;
};
struct cmp
{
bool operator()(s a1,s a2)
{
return a1.y>a2.y;
}
};
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
for(int i=1;i<=2021;i++)
{
for(int j=i+1;j<=2021;j++)
{
if(abs(i-j)<=21)
{
int f=__gcd(i,j);
f=i*j/f;
t[i].push_back({j,f});
t[j].push_back({i,f});
}
}
}
for(int i=1;i<=2021;i++)
{
dis[i]=1e18;
}
priority_queue<s,vector<s>,cmp>q;
dis[1]=0;
q.push({1,0});
//int an=1e18;
while(!q.empty())
{
s g=q.top();
q.pop();
for(auto v:t[g.x])
{
if(dis[v.first]>g.y+v.second)
{
dis[v.first]=g.y+v.second;
q.push({v.first,dis[v.first]});
}
}
}
cout<<dis[2021]<<endl;
}
[蓝桥杯2021初赛] 路径
最新推荐文章于 2024-07-18 21:33:10 发布