German Collegiate Programming Contest 2018
// Coolest Ski Route
#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)
typedef pair<int,int> P;
const int N=;
const int inf=0x3f3f3f3f;
int dis[N];
int n,m;
struct Node{
int to,w;
Node(){}
Node(int TO,int W){
to=TO;
w=W;
}
};
vector<Node>vec[N];
void bfs(){
priority_queue<P,vector<P>,less<P> >que;//队首元素为最长距离
for(int i=;i<=n;i++){
que.push(P(,i));//起初,只有自己到自己
}
while(!que.empty()){
P q=que.top();
que.pop();
int v=q.second;
if(dis[v]>q.first) continue;//比当前的还大,就不用继续往下找了
for(int i=;i<vec[v].size();i++){
Node Nod=vec[v][i];
int t=Nod.to;
if(dis[t]<dis[v]+Nod.w){
dis[t]=dis[v]+Nod.w;//不断更新dis[t]
que.push(P(dis[t],t));
}
}
}
}
int main()
{
scanf("%d%d",&n,&m);
int s,t,c;
for(int i=;i<m;i++)
{
scanf("%d%d%d",&s,&t,&c);
vec[s].push_back(Node(t,c));//有向图
}
memset(dis,,sizeof(dis));//要初始化为0
bfs();
int MAX=-inf;
for(int i=;i<=n;i++){
MAX=max(MAX,dis[i]);//i为终点,dis[i]为到i的最大路径长度
}
printf("%d\n",MAX);
return ;
}
// Coolest Ski Route
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e3+;
struct Node{
int to,w;
Node(){}
Node(int TO,int W){
to=TO;
w=W;
}
};
vector<Node> vs[N];
int d[N],in[N];
void dfs(int v) {
for(int i = ; i < vs[v].size(); i ++) {
Node Nod =vs[v][i];
int u=Nod.to;
if(d[u] < d[v] + Nod.w ) {
d[u] = d[v] + Nod.w;
dfs(u);
}
}
}
int main() {
int n, m;
cin >> n >> m;
for(int i = ; i < m; i ++) {
int u, v, w;
cin >> u >> v >> w;
vs[u].push_back(Node(v,w));
in[v]++;
}
for(int i = ; i <= n; i ++) {
if(!in[i])//本题任意两点之间为单向
dfs(i);
}
int MAX = ;
for(int i = ; i <= n; i ++) MAX = max(MAX, d[i]);
printf("%d\n",MAX);
return ;
}
German Collegiate Programming Contest 2018的更多相关文章
- 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 C. Coolest Ski Route
John loves winter. Every skiing season he goes heli-skiing with his friends. To do so, they rent a h ...
- 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\) ...
随机推荐
- Fleet-运行一个高可用的服务
运行一个高可用的服务 使用CoreOS最大的好处就是你可以以高可用的方式来运行你的服务.接下来我们将部署两个一样的Apache web server容器.然后,我们将通过让一台机器出现故障,fleet ...
- .net framework MVC 下 Hangfire使用,时区,权限
安装 NuGet 上有几个可用的Hangfire 的软件包.如果在ASP.NET应用程序中安装HangFire,并使用Sql Server作为存储器,那么请在Package Manager Conso ...
- .Net平台互操作技术:03. 技术验证
上面两篇文章分别介绍了.Net平台互操作技术面临的问题,并重点介绍了通过P/Invoke调用Native C++类库的技术实现.光说不做是假把式,本文笔者将设计实验来证明P/Invoke调用技术的可行 ...
- android配置android studio not found target android-*.的问题
列:not found target android-25, 打开下载android SDK的工具栏,找到android-25版本下载到你本地的sdk路径下就OK了.
- 【extjs6学习笔记】1.6 初始:本地化
app.json中修改
- Spring 和 Mybatis 整合
Spring 和 Mybatis 整合 Spring本身的Config文件: 在IDEA下面配置好文件后, 在WEB-INF下面有三个配置文件分别是web.xml, applicationContex ...
- Adobe登陆出现Access denied解决方法
当我安装好Adobe Acrobat Reader DC时,想要登陆Adobe账号时被Access denied. 一般说需要梯子,然而本人亲测这种方法不行(香港主机,全局模式下). 一个简单有效的方 ...
- opencv c++编译
g++ image2png.cpp -o test `pkg-config --cflags --libs opencv`
- 关于tomcat的classloader的一点想法
关于tomcat的classloader相关的帖子网上非常多,我觉得比较好的有: https://www.jianshu.com/p/d90e4430b0b9 https://blog.csdn.ne ...
- BCB:使用CppWebBrowser判断网页加载完成
void __fastcall TForm1::CppWebBrowser1DocumentComplete(TObject *Sender, LPDISPATCH pDisp, Variant *U ...