German Collegiate Programming Contest 2018 C. Coolest Ski Route
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的更多相关文章
- German Collegiate Programming Contest 2018 B. Battle Royale
Battle Royale games are the current trend in video games and Gamers Concealed Punching Circles (GCPC ...
- German Collegiate Programming Contest 2018
// Coolest Ski Route #include <iostream> #include <cstdio> #include <cstring> #inc ...
- German Collegiate Programming Contest 2018 A. Attack on Alpha-Zet
题目链接https://nanti.jisuanke.com/t/28852 题目大意是 h*w 的平面,每两个点有且仅有一条路径,类似于封闭的联通空间,然后在这h*w个点中选取(标记为1~N)N个点 ...
- 2018 German Collegiate Programming Contest (GCPC 18)
2018 German Collegiate Programming Contest (GCPC 18) Attack on Alpha-Zet 建树,求lca 代码: #include <al ...
- (寒假GYM开黑)2018 German Collegiate Programming Contest (GCPC 18)
layout: post title: 2018 German Collegiate Programming Contest (GCPC 18) author: "luowentaoaa&q ...
- 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 ...
- (寒假开黑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 ...
- German Collegiate Programming Contest 2015 计蒜课
// Change of Scenery 1 #include <iostream> #include <cstdio> #include <algorithm> ...
- 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\) ...
随机推荐
- idea代码生成功能 live template
一 界面 二 添加 三 编写模板 模板可以通过看其他的模板学习相应语法,难不倒程序员的 四 选择适应范围 五 本人常用的模板 log private static final Logger log = ...
- win10命令行压缩zip文件
1.下载winzip,下载winzip command line(官方) 2.使用命令 "C:\Program Files\WinZip\WZZIP.exe" C:\test\a. ...
- mac下远程win8.1时提示"桌面连接无法验证您希望连接的计算机的身份"的解决办法
在os x下使用远程桌面到win8.1,总出现“远程桌面连接无法验证您希望连接的计算机的身份”的提示. 解决方法:1.网上各种解释,包括防火墙是否打开,是否去掉“仅允许运行使用网络级别身份验证的远程计 ...
- Web 前端安装依赖的时候遇到的问题
- 《Head First 设计模式》之单件模式
单件模式(Singleton) ——确保一个类只有一个实例,并提供全局访问点. 有一些对象其实我们只需要一个,比如线程池.缓存.对话框.处理偏好设置和注册表的对象.日志对象.如果制造出多个实例,就会导 ...
- Android RecycleView实现混合Item布局
首先来看看效果吧: 效果预览.png 本实例来自于慕课网的视屏http://www.imooc.com/video/13046,实现步骤可以自己去观看视屏,这里只记录了下实现的代码. 添加依赖: (1 ...
- linux 下 `dirname $0`(转)
在命令行状态下单纯执行 $ cd `dirname $0` 是毫无意义的.因为他返回当前路径的".".这个命令写在脚本文件里才有作用,他返回这个脚本文件放置的目录,并可以根据这个目 ...
- 访问FTP站点下载文件,提示“当前的安全设置不允许从该位置下载文件”的解决方案
访问FTP站点下载文件,提示“当前的安全设置不允许从该位置下载文件”的解决方案: 打开客戶端浏览器--工具---internet-安全-自定义级别-选择到低到中低. 然后点受信任站点,把你要访问的站点 ...
- 一个普通 iOS 码农的几个小项目相关知识点总结
题记:在开发的路途上,有的人走的很深很远,而对于停留在初级阶段的我来说,还要学的.经历的还有很多... list sqlite 数据库中,当把表里的数据都清空时,下次插入的数据的 id 主键不会从 0 ...
- Linux 的歷史
Unix 狹義作業系統提供應用程式及命令直譯器. 作業系統發展初期並不具可攜性. Bell, GE 及 MIT 合作開發的 "Multice" 系統( 相容分時系統 ). 1969 ...