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 &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_queueShandong Province seventh session of ACM Contest C (Dijkstra algorithm, single source path shortest problem)