【CCF】地铁修建 改编Dijkstra
【题意】
给定有n个点,m条边的无向图,没有平行边和自环,求从1到n的路径中,最长段的最小值(最短路不再是路径和,而是所有段中的最大值)
【AC】
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue> using namespace std;
const int maxn=1e5+;
const int maxm=2e5+;
const int inf=0x3f3f3f3f;
int n,m;
struct edge{
int to;
int nxt;
int w;
}e[*maxm];
struct node{
int id;
int d;
node(int _id,int _d):id(_id),d(_d){}
bool operator < (const node& a) const{
return d>a.d;
}
};
int dis[maxn];
bool vis[maxn];
int head[maxn];
int tot;
void init(){
memset(head,-,sizeof(head));
tot=;
}
void add(int u,int v,int w){
e[tot].to=v;
e[tot].w=w;
e[tot].nxt=head[u];
head[u]=tot++;
} int work(){
memset(dis,inf,sizeof(dis));
memset(vis,false,sizeof(vis));
dis[]=;
priority_queue<node> Q;
Q.push(node(,dis[]));
while(!Q.empty()){
node q=Q.top();
Q.pop();
int u=q.id;
if(vis[u]) continue;
vis[u]=true;
for(int i=head[u];i!=-;i=e[i].nxt){
int v=e[i].to;
int w=e[i].w;
int tmp=max(q.d,w);
if(tmp<dis[v]){
dis[v]=tmp;
Q.push(node(v,dis[v]));
}
}
}
return dis[n]; }
int main(){
while(~scanf("%d%d",&n,&m)){
init();
int u,v,w;
for(int i=;i<=m;i++){
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
int ans=work();
printf("%d\n",ans);
}
return ;
}
【CCF】地铁修建 改编Dijkstra的更多相关文章
- CCF(地铁修建):向前星+dijikstra+求a到b所有路径中最长边中的最小值
地铁修建 201703-4 这题就是最短路的一种变形,不是求两点之间的最短路,而是求所有路径中的最长边的最小值. 这里还是使用d数组,但是定义不同了,这里的d[i]就是表示从起点到i的路径中最长边中的 ...
- CCF地铁修建
问题描述 A市有n个交通枢纽,其中1号和n号非常重要,为了加强运输能力,A市决定在1号到n号枢纽间修建一条地铁. 地铁由很多段隧道组成,每段隧道连接两个交通枢纽.经过勘探,有m段隧道作为候选,两个交通 ...
- CCF CSP 201703-4 地铁修建
博客中的文章均为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201703-4 地铁修建 问题描述 A市有n个交通枢纽,其中1号和n号非常重要,为了加强运输能力,A市决定在1号到n ...
- ccf 201703-4 地铁修建(95)(并查集)
ccf 201703-4 地铁修建(95) 使用并查集,将路径按照耗时升序排列,依次加入路径,直到1和n连通,这时加入的最后一条路径,就是所需要修建的时间最长的路径. #include<iost ...
- csp20170304地铁修建_Solution
ccf20170304地铁修建_Solution 这里最短路为所以从点1到点n的路径中最长的道路的长度. 因为1 ≤ n ≤ 100000,1 ≤ m ≤ 200000,属于稀疏图,所以使用Spfa( ...
- CSP 201703-4 地铁修建 最小生成树+并查集
地铁修建 试题编号: 201703-4 试题名称: 地铁修建 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 A市有n个交通枢纽,其中1号和n号非常重要,为了加强运输能力, ...
- CSP 201703-4 地铁修建【最小生成树+并查集】
问题描述 试题编号: 201703-4 试题名称: 地铁修建 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 A市有n个交通枢纽,其中1号和n号非常重要,为了加强运输能力,A市 ...
- CCF 201703-4 地铁修建(最小生成树)
题意:A市有n个交通枢纽,其中1号和n号非常重要,为了加强运输能力,A市决定在1号到n号枢纽间修建一条地铁.地铁由很多段隧道组成,每段隧道连接两个交通枢纽.经过勘探,有m段隧道作为候选,两个交通枢纽之 ...
- 【CCF】行车路线 改编Dijkstra
[AC] #include<iostream> #include<cstdio> #include<string> #include<cstring> ...
随机推荐
- 在DataGridView控件中显示图片
实现效果: 知识运用: DataGridView控件的DataSource属性 实现代码: private void Form1_Load(object sender, EventArgs e) { ...
- Understanding NFS Caching
Understanding NFS Caching Filesystem caching is a great tool for improving performance, but it is im ...
- ssh整合思想 Spring与Hibernate和Struts2的action整合 调用action添加数据库 使用HibernateTemplate的save(entity)方法 update delete get 等方法crud操作
UserAction类代码: package com.swift.action; import com.opensymphony.xwork2.ActionSupport; import com.sw ...
- cocos2dx 使用XMLHttpRequest时回调status为0的问题
今天使用cocos连接http访问时,使用XMLHttpRequest在pc上反问时正常的返回了status=0,但是在android上去返回status是0,看了一下底层代码, 发现status只有 ...
- Factorialize a Number-freecodecamp算法题目
Factorialize a Number(计算一个整数的阶乘) 要求 给定一个整数,求其阶乘(用字母n来代表一个整数,阶乘代表着所有小于或等于n的整数的乘积) 思路 确定乘的次数 用for循环进行累 ...
- RabbitMQ学习(二):Java使用RabbitMQ要点知识
转 https://blog.csdn.net/leixiaotao_java/article/details/78924863 1.maven依赖 <dependency> <g ...
- JavaScript取出字符串中括号里的内容
/** * 取出中括号内的内容 * @param text * @returns {string} */ export function getBracketStr(text) { let resul ...
- linux SVN安装及配置教程
1.环境centos6.4 2.安装svnyum -y install subversion 3.配置 建立版本库目录mkdir /www/svndata svnserve -d -r /www/sv ...
- HDU 5614 Baby Ming and Matrix tree 树链剖分
题意: 给出一棵树,每个顶点上有个\(2 \times 2\)的矩阵,矩阵有两种操作: 顺时针旋转90°,花费是2 将一种矩阵替换为另一种矩阵,花费是10 树上有一种操作,将一条路经上的所有矩阵都变为 ...
- python基础学习笔记——类的成员
一. 细分类的组成成员 之前咱们讲过类大致分两块区域,如下图所示: 每个区域详细划分又可以分为: class A: company_name = '老男孩教育' # 静态变量(静态字段) __ipho ...