HDU 2680 Choose the best route

Source: Internet
Author: User

Because there are multiple starting points, so what?

1: Reverse build (personal feeling trouble)

2: Building a super starting point

I used the second, simple rough, that is, a new starting point (0), he and all the topic of the beginning of the link, and the distance is 0, and then the template walk

#include <iostream> #include <cstring> #include <vector> #include <algorithm> #define INF 1< <28#define maxn 1010using namespace Std;int n,m,e;vector<int>mapp[maxn];int vaule[maxn][maxn];int VISIT[MAXN ];void Init () {for (int i=0;i<=n;i++) mapp[i].clear (); memset (Vaule,0,sizeof (Vaule));} void input () {for (int i=0;i<m;i++) {int x,y,z;cin>>x>>y>>z;if (!vaule[x][y]) {Mapp[x].push_back ( y); vaule[x][y]=z;} else Vaule[x][y]=min (vaule[x][y],z);} cin>>m;for (int i=0;i<m;i++) {int x;cin>>x;mapp[0].push_back (x);}} int DJ () {int D[maxn];fill (d,d+1+n,inf), Fill (visit,visit+1+n,0);d [0]=0;while (!visit[e]) {//for (int i=0;i<=n;i++) cout<<d[i]<< "";//cout<<endl;int v=-1;for (int i=0;i<=n;i++) {if (!visit[i]&& | D[I]&LT;D[V]) v=i;} Cout<<v<<endl;if (v==-1| | D[v]==inf) return-1;visit[v]=1;for (int i=0;i<mapp[v].size (); i++) {int x=mapp[v][i];d [X]=min (d[x],d[v]+vaule[v][ X]);//cout<<x<< "~" <<d[x]<<endl;}} return d[e];} int main () {Cin.sync_with_stdio (false), while (cin>>n>>m>>e) {init (); input (); Cout<<dj () < <endl;}  return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 2680 Choose the best route

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.