Topic links
To find the shortest path of point 1 to N
Puzzle: Use the heap optimization in Pbds ...
My harvest: Get posture
#include <iostream> #include <cstdio> #include <cstring> #include <ext/pb_ds/priority_queue.hpp
> #define LL Long long #define PA pair<ll,int> #define Llinf 9000000000000000000LL using namespace std;
using namespace __gnu_pbds;
typedef __GNU_PBDS::p riority_queue<pa,greater<pa>,pairing_heap_tag > Heap;
int n,m,cnt,last[1000005];
int T,RXA,RXC,RYA,RYC,RP;
Heap::p oint_iterator id[1000005];
int x, y, Z;
ll dis[1000005]; struct Data{int to,next,v;}
E[10000005];
inline int read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | |
Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}
while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();}
return x*f; } void Insert (int u,int v,int W) {e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;e[cnt].v=w;} void Dijkstra () {h
EAP Q;
for (int i=1;i<=n;i++) Dis[i]=llinf;
Dis[1]=0;id[1]=q.push (Make_pair (0,1));
while (!q.empty ()) {int now=q.top (). Second;q.pop (); for (int i=Last[now];i;i=e[i].next) if (e[i].v+dis[now]<dis[e[i].to]) {DIS[E[I].TO]=E[I].V
+dis[now];
if (id[e[i].to]!=0) q.modify (Id[e[i].to],make_pair (dis[e[i].to],e[i].to));
Else Id[e[i].to]=q.push (Make_pair (dis[e[i].to],e[i].to));
}}} int main () {n=read (); M=read ();
T=read (); Rxa=read (); Rxc=read (); Rya=read (); Ryc=read (); Rp=read ();
int A, B;
for (int i=1;i<=t;i++) {x= (LL) x*rxa+rxc)%RP;
Y= (LL) y*rya+ryc)%RP;
A=min (x%n+1,y%n+1);
B=max (y%n+1,y%n+1);
Insert (A,B,100000000-100*A);
} for (int i=1;i<=m-t;i++) {x=read (), Y=read (), Z=read ();
Insert (x, y, z);
} Dijkstra ();
printf ("%lld", Dis[n]);
return 0; }