Question: Expensive dowry
This question is quite rewarding for you. You can understand it only when templates are frequently typed. You have to think about templates by yourself. You can learn new things from the perspective of warmth, and you can make a summary of the previous graph creation methods, you must use it when you do the question. Otherwise, = NULL.
The meaning of the question is a bit unclear about the exchange condition description. Here, Let's explain that for eight items, the level gap cannot exceed 3, and the leader LV 5, therefore, the LV range that can be exchanged is [] [] [] [] []. You do not need to consider the question, "But if he makes a transaction with a person with a lower position, a person with a higher position will not trade with him. They think this is like indirect contact, and the opposite is true ". The more you see, the more dizzy you are, as long as you meet the above range can be exchanged.
Thinking: when I started to look at the question, my thinking was a little biased. I thought P God could only start his first transaction from the person with the cheapest price and lowest grade, and then I knocked on it... And then .. I couldn't help it anymore. I checked Discuss. Oh, enumeration, I used Dijkstra or Bellman-Ford for the shiniu gate on Discuss, and I still learned some work. Then, I think the SPFA that Bellman-Ford can pass will certainly be able to pass, but I forgot how to think about SPFA .. Review the shortest path And create A diagram. The small details in the middle are not well handled by myself, and the program will not be called, and the P God is called again ....
ME TIME
720kb 32 ms
# Include
# Include
# Include
# Include
# Include const int Size = 99999; const int INF = 1 <20; const int N = 101; const int MMM = 10010; using namespace std; int NN, M, l = 0; struct node {int v, w, next;} edge [MMM]; int p [N], lv [N], num, t; int dis [N], vis [N], lim, low; int q [MMM], head [MMM]; int SPFA (int S, int E) {// printf ("low = % d high = % d \ n", low, lim); int s = 0, e = 0; for (int I = 1; I <= N; I ++) dis [I] = p [1]; dis [S] = 0; q [e ++] = S; vis [S] = 1; while (s <E) {int tmp = q [s ++]; for (int I = head [tmp]; I! = 0; I = edge [I]. next) {if (lv [edge [I]. v]> = low & lv [edge [I]. v] <= lim) & (dis [edge [I]. v]> dis [tmp] + edge [I]. w) {dis [edge [I]. v] = dis [tmp] + edge [I]. w; if (! Vis [edge [I]. v]) {q [e ++] = edge [I]. v; vis [edge [I]. v] = 1 ;}} vis [tmp] = 0;} return dis [E];} void add (int a, int B, int c) // create a graph for the forward direction {edge [t]. v = B; edge [t]. w = c; edge [t]. next = head [a]; head [a] = t; t ++;}/* void Print () {int k, I; for (I = 0; I <= NN; I ++) {if (head [I]) {for (k = head [I]; k! = 0; k = edge [k]. next) {printf ("% d-> % d \ n", I, edge [k]. v, edge [k]. w) ;}}} */int main () {int a, B; while (~ Scanf ("% d", & M, & NN) {l = 0; t = 1; memset (head, 0, sizeof (head )); for (int I = 1; I <= NN; I ++) {scanf ("% d", & p [I], & lv [I], & num); add (0, I, p [I]); for (int j = 0; j