题意:中文题目。。

解题思路:我的做法就是单源最短路中加个记录分数的数组,如果dis[i]到dis[x]的距离可以被优化,那就连记录分数的数组一起优化,如果第二条路和第一条路的距离相等,那就取最大的分数;

代码:#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#define maxn 250001
const int inf=999999;
using namespace std;
struct Edge
{
    int next;
    int to;
    int w;
    int g;
}edge[maxn];
struct node
{
    int num;
    int dist;
    node(int _num=0,int _dist=0):num(_num),dist(_dist){}
    friend bool operator<(node a,node b)
    {
        return a.dist>b.dist;
    }
};
int head[maxn];
int s[maxn];
int n,m,cnt;
int dis[maxn];
int grade[maxn];
int a[maxn];
bool vis[maxn];
void add(int u,int v,int w,int g)
{
    edge[cnt].next=head[u];
    edge[cnt].to=v;
    edge[cnt].w=w;
    edge[cnt].g=g;
    head[u]=cnt++;
}
void dij(int x)
{
    priority_queue<node>que;
    memset(dis,0x3f,sizeof(dis));
    memset(vis,0,sizeof(vis));
    memset(grade,0,sizeof(grade));
    dis[x]=0;
    que.push(node(x,0));
    dis[x]=0;
    grade[x]=a[x];
    while(!que.empty())
    {
        node p=que.top();
        que.pop();
        int now=p.num;
        if(vis[now])
            continue;
        vis[now]=true;
        for(int i=head[now];i!=-1;i=edge[i].next)
        {
            Edge e=edge[i];
            if(dis[e.to]>dis[now]+e.w&&!vis[e.to])
            {
                dis[e.to]=dis[now]+e.w;
                grade[e.to]=grade[now]+e.g;
                que.push(node(e.to,dis[e.to]));
            }
           else if(dis[e.to]==dis[now]+e.w&&!vis[e.to])
            {
                grade[e.to]=max(grade[e.to],grade[now]+e.g);
            }
           // cout<<e.to<<" "<<grade[e.to]<<endl;
        }
    }
    return;
}
int main()
{
    int st,en;
    int x,y,w;
    memset(head,-1,sizeof(head));
    while(cin>>n>>m>>st>>en)
    {
        memset(head,-1,sizeof(head));
        cnt=0;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=1;i<=m;i++)
    {
        cin>>x>>y>>w;
        add(x,y,w,a[y]);
        add(y,x,w,a[x]);
    }
    dij(st);
    cout<<dis[en]<<" "<<grade[en]<<endl;
    }
    return 0;
}

这里注意:双向边,然后链式前向星存图因为没说边的数量,应该要开的极限点。

51nod-1459-迷宫游戏的更多相关文章

  1. 51nod 1459 迷宫游戏(dij)

    题目链接:51nod 1459 迷宫游戏 dij裸题. #include<cstdio> #include<cstring> #include<algorithm> ...

  2. 51nod 1459 迷宫游戏 dijkstra模板

    链接:迷宫游戏 问题 - 51Nod  http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1459 1459 迷宫游戏  基准 ...

  3. 51nod 1459 迷宫游戏【最短路拓展】

    1459 迷宫游戏 基准时间限制:1 秒 空间限制:131072 KB   你来到一个迷宫前.该迷宫由若干个房间组成,每个房间都有一个得分,第一次进入这个房间,你就可以得到这个分数.还有若干双向道路连 ...

  4. 51nod 1459 迷宫游戏 (最短路径—Dijkstra算法)

    题目链接 中文题,迪杰斯特拉最短路径算法模板题. #include<stdio.h> #include<string.h> #define INF 0x3f3f3f3f ],v ...

  5. 51 NOd 1459 迷宫游戏 (最短路径)

    1459 迷宫游戏  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 你来到一个迷宫前.该迷宫由若干个房间组成,每个房间都有一个得分,第一次进入这个房间, ...

  6. 51Nod 1459:迷宫游戏(最短路)

    1459 迷宫游戏  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 你来到一个迷宫前.该迷宫由若干个房间组成,每个房间都有一个得分,第一次进入这个房间, ...

  7. 51nod--1459 迷宫游戏 (dijkstra)

    1459 迷宫游戏 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 你来到一个迷宫前.该迷宫由若干个房间组成,每个房间都有一个得分,第一次进入这个房间,你就可 ...

  8. 51nod1459 迷宫游戏

    1459 迷宫游戏 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 你来到一个迷宫前.该迷宫由若干个房间组成,每个房间都有一个得分,第一次进入这个房间,你 ...

  9. c语言迷宫游戏的实现

    // // main.c // 迷宫游戏代码实现 // #include <stdio.h> #define ROW 6 //宏定义行 #define COL 6 //宏定义列 /** * ...

  10. 用webgl打造自己的3D迷宫游戏

    用webgl打造自己的3D迷宫游戏 2016/09/19 · JavaScript · WebGL 原文出处: AlloyTeam    背景:前段时间自己居然迷路了,有感而发就想到写一个可以让人迷路 ...

随机推荐

  1. PAT A1121 Damn Single (25 分)——set遍历

    "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...

  2. 201904Online Human Action Recognition Based on Incremental Learning of Weighted Covariance Descriptors

    论文标题:Online Human Action Recognition Based on Incremental Learning of Weighted Covariance Descriptor ...

  3. nfs原理及安装配置

    一.简介 二.工作原理 三.安装配置 一.简介 NFS(Network File System)即网络文件系统,它允许网络中的计算机之间通过网络共享资源.将NFS主机分享的目录,挂载到本地客户端当中, ...

  4. tmux 复制粘贴

    tmux版本(tmux 2.3): $tmux -V 要想让tmux和系统剪贴板之间互相复制粘贴,在linux中需要先安装 xclip: sudo apt-get install xclip 然后在 ...

  5. BZOJ 5475: [WC 2019] 数树

    WC2019 数树 解决了一个心头大患 考试的时候本人太智障了QwQ 本文的参考链接,膜了一发rqy的题解 题目链接 Subtask 0 好像可以直接做... 推一推就能发现,是$y^k$,其中$k$ ...

  6. CF809D Hitchhiking in the Baltic States LIS、平衡树

    传送门 看到最长上升子序列肯定是DP 设\(f_i\)表示计算到当前,长度为\(i\)的最长上升子序列的最后一项的最小值,显然\(f_i\)是一个单调递增的序列. 转移:对于当前计算的元素\(x\), ...

  7. cp 命令有坑

    cp 是个很常用的命令, 基本语法为  cp -v  a   b  把文件a 复制为文件b(-v为显示做了什么,这是非常安全的做法,建议新手添加此参数) 参数说明: -a:此选项通常在复制目录时使用, ...

  8. Java HTML to PDF 支持SVG

    尝试一 (现用框架的基础上改动,影响最小化) 最早使用的框架 Xhtmlrenderer,需要把HTML转换成XHTML,引入第二个框架Tidy,Tidy与2010年停止更新,github上的项目也停 ...

  9. 历时25天,我的博客(www.ityouknow.com)终于又活了过来

    时间回到2016年的7月10号,那时候我刚刚开始正式在博客园写博客,博客园的交流氛围很好,但鉴于博客园古老的界面,同时计划创建一个自己独立的博客,毕竟自己的博客怎么折腾都行. 那时候正在研究 Spri ...

  10. Session之Config配置

    <sessionState mode="Off|InProc|StateServer|SQLServer" cookieless="true|false" ...