您当前的位置: 首页 > 

钟钟终

暂无认证

  • 1浏览

    0关注

    233博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

P1576 最小花费(最长路径)

钟钟终 发布时间:2022-02-01 23:18:41 ,浏览量:1

P1576 最小花费 https://www.luogu.com.cn/problem/P1576 一开始以为要记录路径和距离一个个处理,其实想错了。 本题是求长路径,致使100/z中的z值最大,具体代码如下,可用优先队列进行优化,但本题我只用了邻接表存储,复杂度也满足了题目要求。 双向存储,double类型,算两个注意点把!!!

#include 

using namespace std;
typedef long long ll;
const int maxn=5e5+5;
const int inf=0x7fffffff;
struct node
{
    int to,nxt;
    double dis;
}e[maxn];
int n,m,head[maxn],kk,cnt,s,a,b;
double dist[maxn],minn;
bool vis[maxn];
void add_edge(int from,int to,double dis)
{
    e[++cnt].to=to;
    e[cnt].dis=dis;
    e[cnt].nxt=head[from];
    head[from]=cnt;
}
void dijkstra()
{
    dist[s]=1.0;
    while(!vis[s])
    {
        vis[s]=1;minn=0;
        for(int i=head[s];i!=-1;i=e[i].nxt)
        {
            int y=e[i].to;
            if(dist[y]            
关注
打赏
1664378814
查看更多评论
0.0407s