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)