本来想学一下配对堆的...结果学着学着就偏了...

之前 kpm 写过这道题 , 前面的边不理它都能 AC .. 我也懒得去写前面的加边了...

用 C++ pb_ds 库里的 pairing_heap 水过去的...

----------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<ext/pb_ds/priority_queue.hpp>
 
#define rep( i , n ) for( int i = 0 ; i < n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )
#define Rep( i , n ) for( int i = 1 ; i <= n ; ++i )
#define mk make_pair
  

using namespace std;

using namespace __gnu_pbds;
 
typedef long long ll;
typedef pair< ll , int > pli;
 
const ll inf = ll( 1e18 );
const int maxn = 1000000 + 5;
const int maxm = 10000000 + 10;
 
struct edge {
int to;
ll dist;
edge* next;
};
 
edge* pt , E[ maxm ];
edge* head[ maxn ];
 
void edge_init() {
pt = E;
clr( head , 0 );
}
 
inline void add_edge( int u , int v , ll d ) {
pt -> to = v;
pt -> dist = d;
pt -> next = head[ u ];
head[ u ] = pt++;
}
 
__gnu_pbds :: priority_queue< pli , greater< pli > , pairing_heap_tag > :: point_iterator pos[ maxn ];
__gnu_pbds :: priority_queue< pli , greater< pli > , pairing_heap_tag > Q;
 
ll d[ maxn ];
int n;
 
void dijkstra() {
rep( i , n ) d[ i ] = inf;
d[ 0 ] = 0;
Q.push( mk( 0 , 0 ) );
while( ! Q.empty() ) {
int x = Q.top().second;
Q.pop();
for( edge* e = head[ x ] ; e ; e = e -> next ) {
int to = e -> to;
if( d[ to ] > d[ x ] + e -> dist ) {
d[ to ] = d[ x ] + e -> dist;
if( pos[ to ] != 0 )
   Q.modify( pos[ to ] , mk( d[ to ] , to ) );
else 
   pos[ to ] = Q.push( mk( d[ to ] , to ) );
}
}
}
}
 
inline int read() {
int ans = 0;
char c = getchar();
for( ; ! isdigit( c ) ; c = getchar() );
for( ; isdigit( c ) ; c = getchar() ) 
   ans = ans * 10 + c - '0';
return ans;
}
 
void Read() {
n = read();
int m = read() , t = read();
m -= t;
rep( i , 5 ) t = read();
while( m-- ) {
int u = read() , v = read() , d = read();
u-- , v--;
add_edge( u , v , d );
}
}
 
int main() {
freopen( "test.in" , "r" , stdin );
edge_init();
Read();
dijkstra();
cout << d[ n - 1 ] << "\n";
return 0;
}

----------------------------------------------------------------------

3040: 最短路(road)

Time Limit: 60 Sec  Memory Limit: 200 MB
Submit: 1843  Solved: 561
[Submit][Status][Discuss]

Description

N个点,M条边的有向图,求点1到点N的最短路(保证存在)。
1<=N<=1000000,1<=M<=10000000

Input

第一行两个整数N、M,表示点数和边数。
第二行六个整数T、rxa、rxc、rya、ryc、rp。

前T条边采用如下方式生成:
1.初始化x=y=z=0。
2.重复以下过程T次:
x=(x*rxa+rxc)%rp;
y=(y*rya+ryc)%rp;
a=min(x%n+1,y%n+1);
b=max(y%n+1,y%n+1);
则有一条从a到b的,长度为1e8-100*a的有向边。

后M-T条边采用读入方式:
接下来M-T行每行三个整数x,y,z,表示一条从x到y长度为z的有向边。

1<=x,y<=N,0<z,rxa,rxc,rya,ryc,rp<2^31

Output

一个整数,表示1~N的最短路。

Sample Input

3 3
0 1 2 3 5 7
1 2 1
1 3 3
2 3 1

Sample Output

2

HINT

【注释】

请采用高效的堆来优化Dijkstra算法。

Source

BZOJ 3040: 最短路(road) ( 最短路 )的更多相关文章

  1. BZOJ 3040: 最短路(road) [Dijkstra + pb_ds]

    3040: 最短路(road) Time Limit: 60 Sec  Memory Limit: 200 MBSubmit: 2476  Solved: 814[Submit][Status][Di ...

  2. bzoj 1726: [Usaco2006 Nov]Roadblocks第二短路【dijskstra】

    严格次短路模板,用两个数组分别维护最短路和次短路,用dijskstra,每次更新的时候先更新最短路再更新次短路 写了spfa版的不知道为啥不对-- #include<iostream> # ...

  3. poj 3463 Sightseeing( 最短路与次短路)

    http://poj.org/problem?id=3463 Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissio ...

  4. POJ---3463 Sightseeing 记录最短路和次短路的条数

    Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9247   Accepted: 3242 Descr ...

  5. POJ 3463 Sightseeing 【最短路与次短路】

    题目 Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the ...

  6. 最短路和次短路问题,dijkstra算法

    /*  *题目大意:  *在一个有向图中,求从s到t两个点之间的最短路和比最短路长1的次短路的条数之和;  *  *算法思想:  *用A*求第K短路,目测会超时,直接在dijkstra算法上求次短路; ...

  7. UESTC30-最短路-Floyd最短路、spfa+链式前向星建图

    最短路 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) 在每年的校赛里,所有进入决赛的同 ...

  8. hdu1688(dijkstra求最短路和次短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1688 题意:第k短路,这里要求的是第1短路(即最短路),第2短路(即次短路),以及路径条数,最后如果最 ...

  9. CF 672C 两个人捡瓶子 最短路与次短路思想

    C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. apache 配置文件管理

    1. Apache配置系统 从整体来看apache的配置系统包括三个部分: (1) 配置文件:比如 httpd.conf   .htaccess (2) 配置指令:在配置文件 httpd.conf  ...

  2. 数据库水平切分的实现原理解析——分库,分表,主从,集群,负载均衡器(转)

    申明:此文为转载(非原创),文章分析十分透彻,已添加原文链接,如有任何侵权问题,请告知,我会立即删除. 第1章 引言 随着互联网应用的广泛普及,海量数据的存储和访问成为了系统设计的瓶颈问题.对于一个大 ...

  3. python函数callable

    callable(object) 中文说明:检查对象object是否可调用.如果返回True,object仍然可能调用失败:但如果返回False,调用对象ojbect绝对不会成功. 注意:类或函数是可 ...

  4. ISO/IEC14443和15693的对比有何具体区别

    ISO14443 ISO14443A/B:超短距离智慧卡标准.这标准订出读取距离7-15厘米的短距离非接触智慧卡的功能及运作标准,使用的频率为13.56MHz.     ISO14443定义了TYPE ...

  5. beini破解无线

    软件介绍 当你的笔记本有无线网卡却不能上网的时刻,也许你会很焦急. 又或许你的隔壁就有无线网络可以接的时刻,但你却由于米有密码而不能上网.下面我将简介一款可以令你惊讶的软件,奶瓶 有了奶瓶以上疑问都可 ...

  6. xen虚拟机操作整理

    1,登陆物理机器 2,查看物理机建立虚拟机的列表 root:~ # xm li Name ID Mem VCPUs State Time(s) Domain-0 0 49450 8 r----- 52 ...

  7. malloc、calloc、realloc三者的差别

    1.malloc 作用:分配内存块 原型:void *malloc(size_t size);size表示要分配的字节数 返回值:返回一个指向所分配空间的void指针,假设没有足够的内存可用,则返回N ...

  8. c#Winform程序的toolStripButton自己定义背景应用演示样例源代码

    C# Winform程序的toolStrip中toolStripButton的背景是蓝色的,怎样改变背景及边框的颜色和样式呢? 实现此功能须要重写toolStripButton的Paint方法 这里仅 ...

  9. oracle 分组后取每组第一条数据

    ‘数据格式 分组取第一条的效果 sql SELECT * FROM (SELECT ROW_NUMBER() OVER(PARTITION BY x ORDER BY y DESC) rn, test ...

  10. C# Best Practices - Building Good Classes

    Building a Class The last four refer as members Signature Accessiblity modifier (Default:internal) c ...