Test instructions
Well, look directly at the topic, anyway, is also a Chinese problem, not good with a few words to express clearly ~ ~ ~
Topic links
Thinking of solving problems
Because the level gap cannot be traded indirectly, the level of each trade is within a range, the range must contain the High priest's rank, the interval can be enumerated, the High priest level of L, you need to from [l-m,l], has been enumerated to [l,l+m], to ensure that all the points of the transaction level in this range is OK, Then, in the process of shortest circuit processing, the shortest circuit, regardless of the value of the direct purchase of goods, directly all take the form of redemption, and then the resulting array plus the value of directly purchased items, from which to find the minimum value is the answer.
AC Code
#include <vector> #include <algorithm> #include <cstdio> #include <iostream> #include <set > #include <cstring> #include <map> #include <cmath> #include <queue>using namespace std; typedef long LONG Ll;typedef pair<int,int> pii;typedef pair<int,pii> pii;const int maxn = 1e4+5;struct Node { int val,level; int X; Vector<pii> VP; };struct Edge {int from,to,val;}; Node l[maxn];vector<edge> g[maxn];int dis[maxn];bool vis[maxn];int n,m;int Dijkstra () {memset (dis,0x3f,sizeof ( dis)); memset (vis,0,sizeof (VIS)); priority_queue<pii,vector<pii>,greater<pii> > Q; Dis[1] = 0; Q.push (PII (dis[1],1)); while (! Q.empty ()) {PII t = q.top (); Q.pop (); int d = T.first; int u = t.second; for (int i=0;i<g[u].size (); i++) {Edge e = g[u][i]; if (E.val + D < dis[e.to]) {dis[e.to] = e.val + D; Q.push (PII (dis[e.to],e.to)); }}} int ans = 1<<30; for (int i=1;i<=n;i++) {Dis[i] + = L[i].val; ans = min (ans,dis[i]); } return ans; int main (int argc, char const *argv[]) {cin >> M >> N; int A, B; for (int i=1;i<=n;i++) {cin >> l[i].val >> l[i].level >> l[i]. X for (int j=0;j<l[i]. x;j++) {cin >> a >> b; L[i].vp.push_back (PII (A, b)); }} Edge E; int left = max (0,l[1].level-m), right = left + M; int ans = 1<<30; while (left <= L[1].level) {for (int i=0;i<=n;i++) {g[i].clear (); } for (int i=1;i<=n;i++) {for (int j=0;j<l[i]. x;j++) {int next = L[i].vp[j].first; if (L[next].level >= left && l[next].level <= right) {e.from = i; E.to = Next; E.val = L[i].vp[j]. second; G[e.from].push_back (e); }}} left++,right++; int te = Dijkstra (); ans = min (ans,te); } cout << ans << endl; return 0;}
poj1062 Expensive Dowry (enumeration + shortest path)