【题解】:

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

【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 1523 求割点

    思路:对于所有节点,每次找的子树,key[root]++;输出时,对于根节点就输出key[root],对于其它节点i,输出key[i]+1; #include<iostream> #inc ...

  2. Servlet & JSP - HttpSession

    关于 Session 的内容,参考 HTTP - Session 机制 创建和检索 HttpSession 通过 HttpServletRequest.getSession 方法可以获取 HttpSe ...

  3. ActiveMQ(5.10.0) - Building a custom security plug-in

    If none of any built-in security mechanisms works for you, you can always build your own. Though the ...

  4. HDOJ2012素数判定

    素数判定 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. JQuery中操作表单和表格

    一:表单应用 1.HTML中的表单大致由三部分组成 (1).表单便签:包含处理表单数据所用的服务端程序URL,以及数据提交到服务器的方法. (2).表单域:包含文本框.密码框.隐藏域.多行文本框.复选 ...

  6. 强大的数据恢复软件--EasyRecovery专业版

    EasyRecovery 是世界著名数据恢复公司 Ontrack 的技术杰作,它是一个威力非常强大的硬盘数据恢复工具.能够帮你恢复丢失的数据以及重建文件系统.EasyRecovery不会向你的原始驱动 ...

  7. %r与%s的区别

    %r用rper()方法处理对象 %s用str()方法处理对象 有些情况下,两者处理的结果是一样的,比如说处理int型对象. 例一: print "I am %d years old.&quo ...

  8. Appcn 移动开发 前台与服务器数据交互

    第一次写.嘿嘿. 言归正传,这几天开始学习移动开发,使用的是Appcan平台.Appcan平台采用HTML5+CSS3做开发 实现跨平台,正好可以满足我们的业务需求. Appacn和数据库进行交互的方 ...

  9. OpenGL4-绘制旋转的立方体

    代码下载 #include "CELLWinApp.hpp"#include <gl/GLU.h>#include <assert.h>#include & ...

  10. Base64编码原理与应用

    本文内容转自网络,如需详细内容,请参考相关网址. http://my.oschina.net/goal/blog/201032 代码参考:http://blog.csdn.net/prsniper/a ...