UVA 10917-walk Through the Forest (Dijstra)

Source: Internet
Author: User

UVA 10917-walk Through the Forest

Topic links

Test instructions: The company number is 1, the home number is 2, every time does not go back home, backtrack defined as: meet the conditions of the road (A, A, b), meet the existence of a starting from the other than all from a home path is short, ask a few way

Idea: first from home to beg Dijstra, so meet the conditions of the road is D[a] > d[b], this figure is a DAG, in the above DP can find the number of species

Code:

#include <cstdio> #include <cstring> #include <vector> #include <queue>using namespace std;# Define INF 0x3f3f3f3fconst int maxnode = 1005;struct Edge {int u, V, Dist; Edge () {}edge (int u, int v, int dist) {this->u = U;this->v = V;this->dist = dist;}}; struct Heapnode {int d, u; Heapnode () {}heapnode (int d, int u) {this->d = D;this->u = u;} BOOL operator < (const heapnode& c) Const {return d > c.d;}}; struct Dijkstra {int n, m;vector<edge> edges;vector<int> g[maxnode];bool done[maxnode];int D[MAXNODE], p[ maxnode];void init (int tot) {n = tot;for (int i = 0; i < n; i++) g[i].clear (); Edges.clear ();} void Add_edge (int u, int v, int dist) {edges.push_back (Edge (U, V, Dist)); m = Edges.size (); G[u].push_back (m-1);} void print (int e) {//shun xuif (p[e] = =-1) {printf ("%d", E + 1); return;} Print (EDGES[P[E]].U);p rintf ("%d", E + 1);} void Print2 (int e) {//ni xuif (p[e] = = 1) {printf ("%d\n", E + 1); return;} printf ("%d", E + 1);p Rint2 (Edges[p[e]].u);} void Dijkstra (int s) {priority_queue

UVA 10917-walk Through the Forest (Dijstra)

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.