Did a run big data of the shortest-circuiting hanging, vector-based two-dimensional analog adjacency table implementation of the Dijkstra algorithm (* "template")

Source: Internet
Author: User

Code:

#include <stdio.h> #include <string.h> #include <string> #include <vector> #include <    Algorithm> #define INF 2100000000using namespace std;int n;struct node{int dd; int W;}    t;vector<node>q[500001];unsigned int Dis[500001];bool vis[500001];void Dijkstra (int s, int e) {int i, J;    Memset (Vis, false, sizeof (VIS));    for (i=0; i<=n; i++) {dis[i] = INF;    } int len=q[s].size (); for (i=0; i<len; i++) {if (Q[S][I].W < dis[q[s][i].dd]) DIS[Q[S][I].DD]=Q[S][I].W;//DIS number from start point    Group Update} vis[s]=true;        for (int k=0; k<n-1; k++) {int pos, mm=inf;                for (I=1; i<=n; i++) {if (!vis[i] && dis[i]<mm) {//The current node has not been accessed and has a lower weight value Mm=dis[i];            Pos=i;        }} vis[pos]=true;        Update the DIS array len=q[pos].size () again; for (j=0; j<len; J + +) {if (!vis[q[pos][j].dd] && dis[q[pos][j].dd]>q[pos][j]. W+dis[pos]) dis[q[pos][j].dd] = Q[POS][J].W + Dis[pos]; }} printf ("%d\n", Dis[e]);}    int main () {int m;    int i;    int U,v, W;    int S, E;        while (scanf ("%d%d", &n, &m)!=eof) {for (i=0; i<=n; i++) q[i].clear ();            for (i=0; i<m; i++) {scanf ("%d%d%d", &u, &v, &w); T.dd=v;            T.w=w;            Q[u].push_back (t); T.dd=u;            T.w=w;        Q[v].push_back (t);        } scanf ("%d%d", &s, &e);    Dijkstra (S, e); } return 0;}

Did a run big data of the shortest-circuiting hanging, vector-based two-dimensional analog adjacency table implementation of the Dijkstra algorithm (* "template")

Related Article

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.