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\) ...
随机推荐
- 在C#中,为什么大家用httpcontext.current,不直接用HttpContext
HttpContext只是个类名,HttpContext.Current才是一个已实例化的对象..比如这样一个类: class A{ public static A Current{get;set;} ...
- oracle中scott用户下四个基本表SQL语句练习
--选择部门中30的雇员SELECT * from emp where DEPTNO=30;--列出所有办事员的姓名.部门.编号--采用内连接方式,也就是等值链接,也是最常用的链接SELECT ena ...
- 1 误删dbf文件造成ORA-01109: 数据库未打开.
1.cmd-sqlplus /nolog-conn system/pwd as sysdba 2.shutdown immediate; 3.startup mount; 4.alter databa ...
- metaclass元类解析
一.创建类的流程 二.什么是元类 在Python3中继承type的就是元类 示例 # 方式一 class MyType(type): '''继承type的就是元类''' def __init__(se ...
- Selenium常见元素定位方法和操作的学习介绍
参考地址: https://www.cnblogs.com/eastmount/p/4810690.html 这篇文章主要Selenium+Python自动测试或爬虫中的常见定位方法.鼠标操作.键盘操 ...
- JS案例练习 — 给div添加样式选择功能
附加效果图: CSS内容: <style> ; padding:0px} li{list-style:none} body{font:24px 'Microsoft YaHei'; col ...
- safenet 超级狗 加密狗
1.CS程序可以工作正常: 2.BS程序,服务器验证狗,IIS设置32位兼容方法1: dog.SetLibPath,设置查找依赖dll路径: 方法2:默认系统目录 C:\Windows\SysWOW6 ...
- windows环境下Nginx部署及Https设置
一.Nginx安装部署及常用命令. 1.1.其实Nginx是免安装的.直接在官网下载zip包,解压即可,下载地址:http://nginx.org/en/download.html,因为我这边的开发服 ...
- [转]超全!iOS 面试题汇总
转自:http://www.cocoachina.com/programmer/20151019/13746.html 1. Object-c的类可以多重继承么?可以实现多个接口么?Category是 ...
- hdu-2066 一个人的旅行---模板题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2066 题目大意: 求到目标点集合中的最短距离 解题思路: dijkstra算法求出每个点到该点的最短 ...