【题解】:

最短路径问题,保证距离最短的同时,学妹权值最大,哈哈

【code】:

 #include<iostream>
#include<queue>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> #define N 50005
#define INF 100000000
using namespace std; struct Edge
{
int to;
int next;
int w;
int num;
}edge[N<<]; struct Nod
{
int u;
int dis;
int num;
}now,temp; bool operator< (Nod a,Nod b)
{
if(a.dis!=b.dis)
return a.dis>b.dis;
return a.num<b.num;
} int weight[N],head[N],visit[N];
int dis[N];
int ans[N]; void init(int n)
{
int i;
for(i=;i<=n;i++)
{
visit[i] = ;
dis[i] = INF;
head[i] = -;
ans[i]=-;
}
} void Dijkstra(int s)
{
int i,v;
dis[s] = ;
ans[s] = weight[s];
priority_queue<Nod> p_q;
temp.dis = ;
temp.u = s;
temp.num = weight[s];
p_q.push(temp);
while(!p_q.empty())
{
temp = p_q.top();
p_q.pop();
if(visit[temp.u]) continue;
visit[temp.u] = ;
for(i=head[temp.u];i!=-;i=edge[i].next)
{
v = edge[i].to;
if(!visit[v])
{
if(dis[v]>dis[temp.u]+edge[i].w||(dis[v]!=INF&&dis[v]==dis[temp.u]+edge[i].w&&ans[v]<ans[temp.u]+weight[v]))
{
dis[v] = dis[temp.u]+edge[i].w;
ans[v] = ans[temp.u]+weight[v];
now.u = v;
now.dis = dis[v];
now.num = ans[v]; p_q.push(now);
}
}
}
}
} int main()
{
int m,n;
while(~scanf("%d%d",&n,&m))
{
int i;
for(i=;i<n;i++) scanf("%d",weight+i);
int id = ;
init(n);
int a,b,c;
for(i=;i<m;i++)
{
scanf("%d%d%d",&a,&b,&c);
a--,b--;
edge[id].to = b;
edge[id].w = c;
edge[id].next = head[a];
head[a] = id++; //将边 a --> b保存 edge[id].to = a;
edge[id].w = c;
edge[id].next = head[b];
head[b] = id++; //将边 b --> a保存
}
Dijkstra();
printf("%d\n",ans[n-]);
}
return ;
}

Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)的更多相关文章

  1. Contest2037 - CSU Monthly 2013 Oct (problem F :ZZY and his little friends)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=5 [题解]: 没想通这题暴力可以过.... [code]: #inclu ...

  2. Contest2037 - CSU Monthly 2013 Oct (problem B :Scoop water)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=1 [题解]:卡特兰数取模 h(n) = h(n-1)*(4*n-2)/( ...

  3. Contest2037 - CSU Monthly 2013 Oct (problem A :Small change)

    [题解]:二进制拆分 任意一个整数都可以拆分成 2^0 + 2^1 + 2^2 + 2^3 + ....+ m [code]: #include <iostream> #include & ...

  4. Contest2037 - CSU Monthly 2013 Oct (Problem J: Scholarship)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=9 [题解]: 这题卡了一下,卡在负数的情况,负数输出 0 这题主要找到一 ...

  5. Contest2037 - CSU Monthly 2013 Oct(中南大学2013年10月月赛水题部分题解)

    Problem A: Small change 题解:http://www.cnblogs.com/crazyapple/p/3349469.html Problem B: Scoop water 题 ...

  6. csu 10月 月赛 D 题 CX and girls

    Description CX是要赶去上课,为了不迟到必须要以最短的路径到达教室,同时CX希望经过的路上能看到的学妹越多越好.现在把地图抽象成一个无向图,CX从1点出发,教室在N号点,告诉每个点上学妹的 ...

  7. 移动设备和SharePoint 2013 - 第5部分:自定义应用

    博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...

  8. 移动设备和SharePoint 2013 - 第4部分:定位

    博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...

  9. 移动设备和SharePoint 2013 - 第3部分:推送通知

    博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...

随机推荐

  1. poj 3155 最大密度子图

    思路: 这个还是看的胡伯涛的论文<最小割在信息学竞赛中的应用>.是将最大密度子图问题转化为了01分数规划和最小割问题. 直接上代码: #include <iostream> # ...

  2. Linux系统内核制作和内核模块的基础

    Linux系统内核制作 1.清除原有配置与中间文件 x86:  make distclean arm:  make distclean 2.配置内核 x86:  make menuconfig arm ...

  3. linux两种增加交换分区(swap)的方法

    在安装Oracle后,为使Oracle流畅运行,需要手动增加linux的交换分区(相当于Windows下的虚拟内存)的大小,本文介绍两种增加交换分区(swap)的方法. 第一种方法:新建分区 1.fd ...

  4. jQuery选择器容易忽视的小知识大问题

    1 关于检查某个元素在网页上的存在 很多人会惯性的写成  } 其实应该根据获取到元素的长度来判断 if($("#tt").length>0){ //do something博 ...

  5. C# 4 dynamic 动态对象 动态类型转换

    public class User { //使用省缺参数,一般不需要再为多态做各种静态重载了 public User( string name = "anonym", string ...

  6. HDOJ2010水仙花数

    水仙花数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. Android开发—— Native 与 Web 之架构抉择

    前 言 移动App是对URL和搜索引擎的革命,当今移动App开发貌似出现两大阵营:Native 和 Web,各自都认为自己才是未来的趋势,Native操作流畅.迅速,Web开发周期相对较短,还能轻松跨 ...

  8. CSS之导航菜单

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. C# to Maxscript

    I figured I’d do a quick tutorial about something a little more difficult, but still very important. ...

  10. Ajax和JSON基础

    Ajax (核心是XMLHttpRequest对象) 1.XMLHttpRequest对象: request=new XMLHttpRequest()  支持Firefox opera Safari  ...