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\) ...
随机推荐
- SpringBoot | 第七章:过滤器、监听器、拦截器
前言 在实际开发过程中,经常会碰见一些比如系统启动初始化信息.统计在线人数.在线用户数.过滤敏高词汇.访问权限控制(URL级别)等业务需求.这些对于业务来说一般上是无关的,业务方是无需关系的,业务只需 ...
- IE6/IE7下只设置margin-left,左右都有边距问题
CSS代码 div { border: 1px solid red; } .inner { width: 80px; height: 80px; float: left; position: rela ...
- sql 删除字段 出错
1. 删除字段: ALTER TABLE TALE_NAME DROP COLUMN nn; 2.报错: 消息 5074,级别 16,状态 1,第 1 行对象'DF__WorkOrder__I ...
- spring transaction 初识
spring 事务初识 1.spring事务的主要接口,首先盗图一张,展示出spring 事务的相关接口.Spring并不直接管理事务,而是提供了多种事务管理器,他们将事务管理的职责委托给Hibern ...
- vue地址插件多级联动自适应 + github地址
https://github.com/cqzyl/vue-manyAddress
- form表单上传域(type="file")的使用----上传文件
一,单个文件的上传 1.html/jsp页面 <%@ page language="java" contentType="text/html; charset=UT ...
- 使用visio创建数据库模型
使用软件:visio 2007 下载地址:https://pan.baidu.com/s/1i4LG1Id 主要参考:http://blog.csdn.net/zhang_xinxiu/article ...
- Python开发环境Wing IDE如何进行命令行调试
Wing IDE专业的调试探针提供了一种强大的方法来发现和解决复杂的错误.这很像Python Shell但允许用户直接参与进已经暂停的调试程序中: 通过键入在刚才发生异常的地方键入下列数值进行尝试: ...
- web安全防御之RASP技术
作者: 我是小三 博客: http://www.cnblogs.com/2014asm/ 由于时间和水平有限,本文会存在诸多不足,希望得到您的及时反馈与指正,多谢! 0x00:we ...
- Nagios-4.1.1 (OpenLogic CentOS 7.2)
平台: CentOS 类型: 虚拟机镜像 软件包: apache2.4.6 nagios 4.1.1 php5.4.16 devops monitoring nagios open-source ph ...