bzoj3040 Shortest Road Road Dij+heap__bzoj

Source: Internet
Author: User

TMD the space card of this problem my eggs are broken.
1e6 of points, 1e7 of the edges, I open 3 1e7 of the array is MLE. You have the ability to turn it down a little bit.
.. Experienced the process of pairing heap--> Ponachi (handwriting)--> handwritten pairing heap from the priority queue-->stl. A dij I wrote all night and I was drunk.
Finally, you have to use the Hzwer STL pairing heap, space can open a little bit more heart.

#include <iostream> #include <cstdio> #include <cstring> #include <ext/pb_ds/priority_queue.hpp
> #define LL 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; }

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.