Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)
【题解】:
最短路径问题,保证距离最短的同时,学妹权值最大,哈哈
【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)的更多相关文章
- 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 ...
- 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)/( ...
- Contest2037 - CSU Monthly 2013 Oct (problem A :Small change)
[题解]:二进制拆分 任意一个整数都可以拆分成 2^0 + 2^1 + 2^2 + 2^3 + ....+ m [code]: #include <iostream> #include & ...
- Contest2037 - CSU Monthly 2013 Oct (Problem J: Scholarship)
http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=9 [题解]: 这题卡了一下,卡在负数的情况,负数输出 0 这题主要找到一 ...
- Contest2037 - CSU Monthly 2013 Oct(中南大学2013年10月月赛水题部分题解)
Problem A: Small change 题解:http://www.cnblogs.com/crazyapple/p/3349469.html Problem B: Scoop water 题 ...
- csu 10月 月赛 D 题 CX and girls
Description CX是要赶去上课,为了不迟到必须要以最短的路径到达教室,同时CX希望经过的路上能看到的学妹越多越好.现在把地图抽象成一个无向图,CX从1点出发,教室在N号点,告诉每个点上学妹的 ...
- 移动设备和SharePoint 2013 - 第5部分:自定义应用
博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...
- 移动设备和SharePoint 2013 - 第4部分:定位
博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...
- 移动设备和SharePoint 2013 - 第3部分:推送通知
博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...
随机推荐
- CSS—换行
关于文本溢出换行问题,先看下涉及到换行的相关属性,查看:http://www.w3school.com.cn 一.word-break 定义:word-break 属性规定自动换行的处理方法. 值 描 ...
- linux下vsftpd的安装与配置说明
问题: 1.530 Permission denied.答:配置文件中userlist_enable=YES(如果启用即YES,则看userlist_deny=YES/NO,如果为NO,则要把登录的用 ...
- 解决oracle归档日志写满了(ORA-00257)的问题
解决ORA-00257: archiver error. Connect internal only, until freed 此问题属于归档日志满了. 解决办法: SQL> select * ...
- IOS 图片全屏预览
如果你感觉累,那就对了那是因为你在走上坡路..这句话似乎有点道理的样子,时常提醒自己无论走到哪都不要忘记自己当初为什么出发.有时想想感觉有的东西可以记录一下,就把它记录下来吧,这次想写一下关于单张图片 ...
- 移动端高清、多屏适配方案 [来源:http://div.io/topic/1092]
Lovesueee 发布于 8 月前 移动端高清.多屏适配方案 背景 开发移动端H5页面 面对不同分辨率的手机 面对不同屏幕尺寸的手机 视觉稿 在前端开发之前,视觉MM会给我们一个psd文件,称之为视 ...
- 抛弃 CSS Hacks 后的浏览器兼容方案
一般情况下的浏览器兼容需要考虑 IE6/7/8 三种 IE 版本,当然在 IE9 开始逐步推向市场后,又会有更多的衍生版本.所以我目前只考虑 IE7~9 版本的兼容情况.涉及到的条件注释代码如下: & ...
- TransparentBlt函数的使用注意事项
今天客户需要在软件上需要添加一个自己公司的Logo,要求使用镂空透明的形式展现,本来以为很简单的工作没想到在MFC下这么复杂.Logo为BMP格式,白色背景. 以为和在按钮上显示控件差不多,先导入BI ...
- 一些常用sqlite语句
1,如果表不存在就新建一个 CComBSTR bstrCreatBat(L”CREATE TABLE IF NOT EXISTS tb_Name (\ rowIdIndex INTEGER PRIM ...
- c# Aes加解密和对象序列化
aes加解密 public class AesCryptto { private string key = "hjyf57468jhmuist"; private string i ...
- sql server返回插入数据表的id,和插入时间
假设要插入数据的数据表结构如下