Basic algorithm of Recheck graph theory

Source: Internet
Author: User

I know what I'm doing.

Statement:

structedge{intY,v,next;} E[MAXN+ -];intlink[maxn+ -];intlen=0;voidPushintXxintYyintVV) {e[++len].next=link[xx]; link[xx]=len;e[len].v=vv;e[len].y=yy;}intMain () {F (I,1, N) {scanf ("%d%d%d",&xx,&yy,&ZZ);        Push (XX,YY,ZZ);    Push (YY,XX,ZZ); }}

Transfer package:

void floyed () {    f (k,1, N) F (        I,1, N)            F (J,1, N)                 if (Dis[i][k]+dis[k][j]<dis[i][j]) // If there is a bit of k, so that the path of i-->k plus k-->j is shorter than i-->j, the path to update i~j is shorter and is recorded in path                    Dis[i][j]=dis[i][k]+dis[k][j],path[i][j]=K;}

Single source non-negative shortest path:

voidDijkstraintSt) {F (i,1, N) dis[i]=A[st][i]; memset (Vis,0,sizeof(VIS)); VIS[ST]=1;d is[st]=0; F (i,1, N-1)    {        intmaxn=INF; intk=0; F (J,1, N) {            if((!vis[j]) && (dis[j]<MAXN)) {MAXN=Dis[j]; K=J; }        }        if(k==0)return; VIS[K]=1; F (J,1, N)//since the outer layer is the I loop, K is replaced by dis (the distance from St to dis[n] so that only one layer of loop can be used to update points with floyed        {            if(!vis[j]&&[k]+a[k][j]<dis[j])//if the nearest point to the Origin K plus K to J (1~n) is closer (and not accessed) than the St to J distance, the path is updated to a shorter one;dis[j]=dis[k]+A[k][j]; }    }}

Basic algorithm of Recheck graph theory

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.