Shandong Province seventh session of ACM Contest C (Dijkstra algorithm, single source path shortest problem)

Source: Internet
Author: User

Test instructions: Given 0-n+1 points, and M-bars, you find a short circuit from 0 to n+1, and the output is connected to the 0 node ...

Analysis: It is obvious, is the Dijkstra algorithm, but the special is to output with 0 connected edge, so we searched backwards, also from n+1 found 0,

Then we can find the side which is connected with 0, and pay attention to the time of judging the equal value. It was wrong to write many times, that is, the boundary was not considered.

The code is as follows:

#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector > #include <queue> #include <cstring>using namespace std;const int INF = 0x3f3f3f3f;const int MAXN = 1000 + 1    00;int n;struct edge{int from, to, Dist;    Edge (int u, int v, int d): From (U), to (v), Dist (d) {}};struct headnode{int d, u; Headnode (int dd, int uu): D (DD), U (UU) {} BOOL operator < (const headnode &AMP;RHS) const {return d > R    HS.D;    }};struct dijkstra{int m;    Vector<edge> edges;    Vector<int> G[MAXN];    BOOL DONE[MAXN];    int D[MAXN];    int P[MAXN];        void Init () {for (int i = 0; I <= n+1; ++i) g[i].clear ();    Edges.clear ();        } void Addedge (int f, int t, int d) {Edges.push_back (Edge (f, T, D));        m = Edges.size ();    G[f].push_back (m-1);        } void Dijkstra (int s) {priority_queue

Shandong Province seventh session of ACM Contest C (Dijkstra algorithm, single source path shortest problem)

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.