Bzoj 3040 Shortest Path (road) heap optimization Dijkstra__bzoj

Source: Internet
Author: User

The shortest way to the topic.


Train of thought: shortest way.

Post a more efficient heap optimization dij template.


CODE:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define _max
1000010 #define MAX 10000010 using namespace std;

#define MIN (a,b) ((a) < (b) a:b) long long f[_max];
	
	struct heap{int num[_max],pos[_max],size;
				void pushup (int p) {while (P > 1) {if (F[num[p]] < f[num[p >> 1]]) {swap (num[p],num[p >> 1]);
				Swap (Pos[num[p]],pos[num[p >> 1]]);
			P >>= 1;
		else break;
		} void Insert (Long long x) {num[++size] = x;
		POS[X] = size;
	Pushup (size);
		} void Pop () {pos[num[1]] = 0;
		NUM[1] = num[size--];
		if (size) pos[num[1]] = 1;
		int now = 2;
			while (now < size) {if (F[num[now + 1]] < F[num[now]) ++now;
				if (F[num[now]] < F[num[now >> 1]) {swap (Num[now],num[now >> 1]);
				Swap (Pos[num[now]],pos[num[now >> 1]]);
			Now <<= 1;
		else break;

}}}heap;
int points,edges;
Long Long T,RXA,RXC,RYA,RYC,RP; int Head[_Max],total;

int Next[max],aim[max],length[max];
	inline void Add (int x,int y,int len) {next[++total] = head[x];
	Aim[total] = y;
	Length[total] = len;
HEAD[X] = total;
	} void Dijkstra () {memset (f,0x3f,sizeof (f));
	F[1] = 0; for (int i = 1; I <= points; ++i) heap.
	Insert (i); while (heap.size) {int x = heap.num[1]; heap.
		Pop (); for (int i = head[x]; i = next[i]) if (F[aim[i]] > F[x] + length[i]) f[aim[i] = f[x] + length[i],heap.
	Pushup (Heap.pos[aim[i]]);
	int main () {cin >> points >> edges;
	CIN >> T >> rxa >> rxc >> rya >> ryc >> RP;
	int x = 0,y = 0,z = 0;
	int a,b;
		for (int i = 1; I <= T; ++i) {x = (long long) x * rxa + rxc)% RP;
		y = (long Long) y * rxa + rxc)% RP;
		A = min (x% points + 1,y% points + 1);
		b = y% points + 1;
	if (a!= b) Add (a,b,1e8-100 * a);
		for (int i = T + 1; I <= edges ++i) {scanf ("%d%d%d", &x,&y,&z);
	ADD (X,Y,Z);
	} Dijkstra (); cout << F[poINTs] << Endl;
return 0; }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.