社区讨论

同样都是dijkstra + heap优化,我的28pts 别人的100pts

P4568[JLOI2011] 飞行路线参与者 2已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@lo1ixix1
此快照首次捕获于
2023/10/22 21:48
2 年前
此快照最后确认于
2023/11/02 22:42
2 年前
查看原帖
我写的
CPP
// void dijkstra() {
//     memset(d,0x3f,sizeof(d));
//     priority_queue<int,vector<int>,greater<int> > heap;
//     d[s] = 0;
//     heap.push(s);
//     while(heap.size()) {
//         int fr = heap.top();
//         heap.pop();
//         if(st[fr]) continue;
//         st[fr] = 1;
//         for(int i = h[fr];i;i = e[i].ne) {
//             int j = e[i].to,w = e[i].w;
//             if(d[j] > d[fr] + w) {
//                 d[j] = d[fr] + w;
//                 heap.push(j);
//             }
//         }
//     }
// }
别人写的
CPP

void dijkstra(int s)
{
    memset(d,0x3f,sizeof(d));
    d[s]=0;
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > points;
    points.push(make_pair(0,s));
    while(!points.empty())
    {
        int u=points.top().second;
        points.pop();
        if(!st[u])
        {
            st[u]=1;
            for(int i=h[u];i;i=e[i].ne)
            {
                int to=e[i].to;
                if(d[to]>d[u]+e[i].w) 
                {
                    d[to]=d[u]+e[i].w;
                    points.push(make_pair(d[to],to));
                }
            }
        }
    }
}

回复

3 条回复,欢迎继续交流。

正在加载回复...