Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一遍 Dij,维护当前看到的最大Level和最小Level作为判断条件核心代码: void dijkstra() { dis[1] = 0; lmi[1] = lma[1] = L[1]; res = min(res, dis[1] + w[1]); for (int i = 0; i < n; ++i) { int t = -1; for (int j = 1; j <= n; ++j) { if (!st[j] && (t == -1 || dis[j] < dis[t])) { t = j; } } st[t] = 1; for (int j = 1; j <= n; ++j) { int mi = min(lmi[t], L[j]), ma = max(lma[t], L[j]), ga = abs(mi - ma); if (g[t][j] != INF && ga <= M) { dis[j] = min(dis[j], dis[t] + g[t][j]); lmi[j] = mi; lma[j] = ma; res = min(res, dis[j] + w[j]); } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator