题意:中文题目。。

解题思路:我的做法就是单源最短路中加个记录分数的数组,如果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 A1102 Invert a Binary Tree (25 分)——静态树,层序遍历,先序遍历,后序遍历

    The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote ( ...

  2. nfs原理及安装配置

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

  3. 13-(基础入门篇)系统教程演示(GPRS模块)

    https://www.cnblogs.com/yangfengwu/p/9966702.html 前几节作为基础教程和系统教程的开端,有了前面的基础才更好的学习基础教程和系统教程. https:// ...

  4. ueditor保存出现 从客户端(Note="<p>12345</p>")中检测到有潜在危险的 Request.Form 值

    检测到有潜在危险的 Request.Form 值   这种问题是因为你提交的Form中有HTML字符串,例如你在TextBox中输入了html标签,或者在页面中使用了HtmlEditor组件等,解决办 ...

  5. keystone系列一:keystone基础

    一 什么是keystone keystone是OpenStack的身份服务,暂且可以理解为一个'与权限有关'的组件. 二 为何要有keystone Keystone项目的主要目的是为访问opensta ...

  6. java线程池和中断总结

    目录 java线程池和中断总结 一. 线程池的使用 二. java中断机制 中断的处理 三. 线程间通信机制总结 java线程池和中断总结 本系列文是对自己学习多线程和平时使用过程中的知识梳理,不适合 ...

  7. Charles使用详解

    前言: Charles是在 Mac 下常用的网络封包截取工具,在做移动开发时,我们为了调试与服务器端的网络通讯协议,常常需要截取网络封包来分析. 一.主界面介绍       二.网页抓包 启动 Cha ...

  8. hdu 3038 给区间和,算出多少是错的

    参考博客 How Many Answers Are Wrong Problem Description TT and FF are ... friends. Uh... very very good ...

  9. pair work结对编程(张艺 杨伊)

    一.结对编程人员: 张艺(学号后三位:185) 杨伊(学号后三位:151) 二.这是我们工作的样子:(图片) 三.结对编程优缺点:  优点:  1.结对编程时间紧密,在一定程度上可以督促双方学习,提高 ...

  10. github 心得体会

     https://github.com/xu123/text 学习了很多知识感觉很有趣 git config :配置git git add:更新working directory中的文件至stagin ...