John loves winter. Every skiing season he goes heli-skiing with his friends. To do so, they rent a helicopter that flies them directly to any mountain in the Alps. From there they follow the picturesque slopes through the untouched snow.

 Of course they want to ski on only the best snow, in the best weather they can get. For this they use a combined condition measure and for any given day, they rate all the available slopes.

 Can you help them find the most awesome route?

 Input Format
The input consists of: one line with two integers nn ( \le n \le )(≤n≤) and mm ( \le m \le )(≤m≤),where nn is the number of (-indexed) connecting points between slopes and mm is the number of slopes.
mm lines, each with three integers ss,tt,cc ( \le s,t \le n, \le c \le )(≤s,t≤n,≤c≤) representing a slopefrom point ss to point tt with condition measure cc.
Points without incoming slopes are mountain tops with beautiful scenery, points without outgoing slopes are valleys. The helicopter can land on every connecting point, so the friends can start and end their tour at any point they want. All slopes go downhill, so regardless of where they start, they cannot reach the same point again after taking any of the slopes. Output Format
Output a single number nn that is the maximum sum of condition measures along a path that the friends could take Hint 样例输入1 复制 样例输出1 复制 样例输入2 复制 样例输出2 复制 题目来源
German Collegiate Programming Contest ​

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
typedef long long ll;
#define lowbit(x) (x&(-x))
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
using namespace std;
#define pi acos(-1)
#define P pair<ll,ll>
const int N =5e3+;//开始把B设为了1000,一直 段错误,m <=5000
const ll inf =1e12+;
int n,m;
ll u,v,w,cnt;
ll d[N],head[N];
struct Edge{
ll fr,to,val,nex;
Edge(){}
Edge(ll fr,ll to,ll val,ll nex):fr(fr),to(to),val(val),nex(nex){}
}e[N*];
void add(ll u,ll v,ll w){
e[cnt].fr=u;
e[cnt].to=v;
e[cnt].val=w;
e[cnt].nex=head[u];
head[u]=cnt++;
}
void init()
{
for(int i =;i<N;i++){
d[i] = ;//求最大值
head[i] = -;
}
cnt = ;
}
void bfs()
{
priority_queue<P,vector<P>,greater<P> >Q;
for(int i =;i<=n;i++)
Q.push(P(,i));//终点为I的路线的距离为0(i到i)
while(!Q.empty())
{
P tmp = Q.top();
Q.pop();
ll v= tmp.second;
if(d[v] > tmp.first) continue;//距离短的路线不用走了。
for(ll i=head[v];i!=-;i=e[i].nex){
Edge ee =e[i];
ll t= e[i].to;
if(d[t]<d[v]+ee.val){
d[t]=d[v]+ee.val;
Q.push(P(d[t],t));
}
} }
}
int main()
{
scanf("%d%d",&n,&m);
init();
for(int i=;i<m;i++){
scanf("%lld%lld%lld",&u,&v,&w);
add(u,v,w);//有向图
}
bfs();
ll maxx = -inf;
for(int i =;i<=n;i++) maxx=max(maxx,d[i]);//找到一条路线距离最长
printf("%lld\n",maxx);
return ;
}

German Collegiate Programming Contest 2018​ C. Coolest Ski Route的更多相关文章

  1. German Collegiate Programming Contest 2018​ B. Battle Royale

    Battle Royale games are the current trend in video games and Gamers Concealed Punching Circles (GCPC ...

  2. German Collegiate Programming Contest 2018​

    // Coolest Ski Route #include <iostream> #include <cstdio> #include <cstring> #inc ...

  3. German Collegiate Programming Contest 2018​ A. Attack on Alpha-Zet

    题目链接https://nanti.jisuanke.com/t/28852 题目大意是 h*w 的平面,每两个点有且仅有一条路径,类似于封闭的联通空间,然后在这h*w个点中选取(标记为1~N)N个点 ...

  4. 2018 German Collegiate Programming Contest (GCPC 18)

    2018 German Collegiate Programming Contest (GCPC 18) Attack on Alpha-Zet 建树,求lca 代码: #include <al ...

  5. (寒假GYM开黑)2018 German Collegiate Programming Contest (GCPC 18)

    layout: post title: 2018 German Collegiate Programming Contest (GCPC 18) author: "luowentaoaa&q ...

  6. ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018

    ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syr ...

  7. (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

    layout: post title: (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) au ...

  8. German Collegiate Programming Contest 2015 计蒜课

    // Change of Scenery 1 #include <iostream> #include <cstdio> #include <algorithm> ...

  9. 2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)(9/11)

    $$2017-2018\ ACM-ICPC\ German\ Collegiate\ Programming\ Contest (GCPC 2017)$$ \(A.Drawing\ Borders\) ...

随机推荐

  1. Java并发编程的艺术,解读并发编程的优缺点

    并发编程的优缺点 使用并发的原因 多核的CPU的背景下,催生了并发编程的趋势,通过并发编程的形式可以将多核CPU的计算能力发挥到极致,性能得到提升. 在特殊的业务场景下先天的就适合于并发编程. 比如在 ...

  2. 虚拟机安装CentOS7 Minimal、jdk和hadoop

    虚拟机安装CentOS7 Minimal.jdk和hadoop Table of Contents 1. 安装版本 2. PD安装 3. vim安装和配置 4. 主机名变为bogon的解决办法 5. ...

  3. Spring cloud Eureka 服务治理(搭建服务注册中心)

    服务之类是微服务架构中最为核心的基础模块,它主要用来实现各个微服务实例的自动化注册和发现. 1. 服务注册 在服务治理框架中,通常会构建一个注册中心,每个服务单元向注册中心登记自己提供的服务,将主机. ...

  4. redis---安全设置

    redis的安全性是通过设置口令来实现的. 首先打开redis的配置文件,我的是在/etc/redis/redis.conf,个人的路径可能会有不同,可以自行查找. 打开redis.conf文件以后, ...

  5. 六、C++离散傅里叶逆变换

    C++离散傅里叶逆变换 一.序言: 该教程承接上文的离散傅里叶变换,用于进行离散傅里叶逆变换. 二.设计目标 对复数数组进行离散傅里叶逆变换,并生成可供使用的图像类. 三.详细步骤 输入:经傅里叶变换 ...

  6. 一、基于Qt的图像矩形区域改色

    Qt环境下图像的打开和涂色 一.设计目标 能够在 Qt QtCreator 环境下打开常用图像格式文件,诸如 bmp.jpg.png 图像等,然后将他们转化为 Qt 中的 QImage 类,并进行矩形 ...

  7. WIN7 64位对Excel操作异常

    在本地做Excel导出功能的测试时,报出“检索COM 类工厂中CLSID 为 {00024500-0000-0000-C000-000000000046}的组件时失败”的异常,知道要对Excel进行D ...

  8. bzoj4622 [NOI 2003] 智破连环阵

    Description B国在耗资百亿元之后终于研究出了新式武器——连环阵(Zenith Protected Linked Hybrid Zone).传说中,连环阵是一种永不停滞的自发性智能武器.但经 ...

  9. 全面了解linux情况常用命令

    查看linux服务器CPU详细情况1. 显示CPU个数命令 # cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc ...

  10. Problem D: 双向冒泡排序

    Problem D: 双向冒泡排序 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 447  Solved: 197[Submit][Status][We ...