二次联通门 : LibreOJ #119. 最短路

/*
LibreOJ #119. 最短路 堆优化的Dijkstra */
#include <cstring>
#include <cstdio>
#include <queue> #define Max 6000 void read (int &now)
{
now = ;
register char word = getchar ();
while (word < '' || word > '')
word = getchar ();
while (word >= '' && word <= '')
{
now = now * + word - '';
word = getchar ();
}
} struct Data
{
int Id;
int dis; bool operator < (const Data &now) const
{
return this->dis > now.dis;
} Data (int __Id, int __dis) : Id (__Id), dis (__dis) {}; Data () {};
}; class Dijkstra_Type
{ private : int __to[Max << ], __next[Max << ];
int __dis[Max << ]; int Edge_Count;
int edge_list[Max];
bool visit[Max]; int dis[Max]; public : void Insert_edge (int from, int to, int dis)
{
Edge_Count ++; __to[Edge_Count] = to;
__next[Edge_Count] = edge_list[from];
edge_list[from] = Edge_Count; Edge_Count ++; __to[Edge_Count] = from;
__next[Edge_Count] = edge_list[to];
edge_list[to] = Edge_Count; __dis[Edge_Count] = __dis[Edge_Count - ] = dis;
} int Dijkstra (int Start, int End)
{
std :: priority_queue <Data> Queue; memset (dis, 0x3f, sizeof dis); Data now ; for (Queue.push (Data (Start, )), dis[Start] = ; !Queue.empty (); Queue.pop ())
{
now = Queue.top (); if (visit[now.Id])
continue; visit[now.Id] = true; for (int i = edge_list[now.Id]; i; i = __next[i]) if (dis[__to[i]] > dis[now.Id] + __dis[i])
{
dis[__to[i]] = dis[now.Id] + __dis[i];
Queue.push (Data (__to[i], dis[__to[i]]));
}
}
return dis[End];
}
}; Dijkstra_Type Make; int main (int argc, char *argv[])
{
int N, M;
int x, y, z; int S, T;
for (read (N), read (M), read (S), read (T); M --; )
{
read (x);
read (y);
read (z); Make.Insert_edge (x, y, z);
} printf ("%d", Make.Dijkstra (S, T)); return ;
}

LibreOJ #119. 最短路的更多相关文章

  1. LibreOJ #119. 最短路 (堆优化dijkstra)

    题目描述 给一个 n(1≤2500≤n) n(1 \leq 2500 \leq n)n(1≤2500≤n) 个点 m(1≤6200≤m) m(1 \leq 6200 \leq m)m(1≤6200≤m ...

  2. 【LibreOJ】#6354. 「CodePlus 2018 4 月赛」最短路 异或优化建图+Dijkstra

    [题目]#6354. 「CodePlus 2018 4 月赛」最短路 [题意]给定n个点,m条带权有向边,任意两个点i和j还可以花费(i xor j)*C到达(C是给定的常数),求A到B的最短距离.\ ...

  3. LibreOJ 题解汇总

    目录 #1. A + B Problem #2. Hello, World! #3. Copycat #4. Quine #7. Input Test #100. 矩阵乘法 #101. 最大流 #10 ...

  4. HDU-6386-最短路

    Age of Moyu Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Tot ...

  5. [日常摸鱼]UVA393 The Doors 简单计算几何+最短路

    The  Boy Next   Doors 题意:给定一个固定大小的房间($x,y$的范围都是$[0,10]$),有$n$个墙壁作为障碍(都与横坐标轴垂直),每个墙壁都有两扇门分别用四个点来描述,起点 ...

  6. L3-007 天梯地图 (30分) 最短路+dp

    最短路+dp思路:nuoyanli 520 Let's play computer game 输入样例1: 10 15 0 1 0 1 1 8 0 0 1 1 4 8 1 1 1 5 4 0 2 3 ...

  7. P3376 【模板】网络最大流——————Q - Marriage Match IV(最短路&最大流)

    第一道题是模板题,下面主要是两种模板,但都用的是Dinic算法(第二个题也是) 第一题: 题意就不需要讲了,直接上代码: vector代码: 1 //invalid types 'int[int]' ...

  8. bfs输出路径 && 最短路(迪杰斯特拉)输出路径

    问题描述 解决方法 1.像第一个问题那就是最短路问题(我代码采用迪杰斯特拉算法)实现 2.换乘次数最少,那就用bfs广搜来寻找答案.但是我的代码不能保证这个最少换乘是最短路程 代码 1 #includ ...

  9. 2019HDU多校第一场 6582 Path 【最短路+最大流最小割】

    一.题目 Path 二.分析 首先肯定要求最短路,然后如何确定所有的最短路其实有多种方法. 1 根据最短路,那么最短路上的边肯定是可以满足$dist[from] + e.cost = dist[to] ...

随机推荐

  1. 怎样手写实现 new 命令的功能

    实现new命令的功能, 首先需要知道new命令都做了些什么: 第一步: 创建一个空对象, 作为实例对象的容器; 第二步: 将空对象的prototype指向构造函数的prototype; 第三步: 将空 ...

  2. 洛谷 P1047 校门外的树(待完善)

    链接:https://www.luogu.org/problemnew/show/P1047 题目: 题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是11米.我们可以把马路看 ...

  3. 重装win7后如何恢复ubuntu引导

    在重装系统之后,开机启动界面的ubuntu引导不见了,直接进入新安装的window系统中.下面是如何恢复ubuntu引导的方法: 1)准备一张ubuntu系统安装盘: 2)将ubuntu系统安装盘放入 ...

  4. Opencl 学习笔记

    1. HelloWorld

  5. Ajax的学习

    AJAX的学习 AJAX的简介 AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX ...

  6. CVE-2019-0214: Apache Archiva arbitrary file write and delete on the server

    CVE-2019-0214: Apache Archiva arbitrary file write and delete on the server Severity: Medium Vendor: ...

  7. spring-security配置和原理简介

    SpringSecurity3的核心类有三种 1.URL过滤器或方法拦截器:用来拦截URL或者方法资源对其进行验证,其抽象基类为AbstractSecurityInterceptor 2.资源权限获取 ...

  8. macro 标签,和静态文件,以及templates

    1 模板 -Templates 1 什么是模板 模板,在Flask中就是允许响应给用户看的网页在模板中,允许包含“占位变量”来表示动态的内容 模板最终也会被解析成字符串再响应给客户端,这一过程通常称为 ...

  9. Kubernetes 的 Client Libraries 的使用

    说明 kubernetes 估计会成为 linux 一样的存在,client-go 是它的 go sdk,client-go/examples/ 给出了一些用例,但是数量比较少. api Resour ...

  10. 《python解释器源码剖析》第12章--python虚拟机中的函数机制

    12.0 序 函数是任何一门编程语言都具备的基本元素,它可以将多个动作组合起来,一个函数代表了一系列的动作.当然在调用函数时,会干什么来着.对,要在运行时栈中创建栈帧,用于函数的执行. 在python ...