Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一遍 Dij,维护当前看到的最大Level和最小Level作为判断条件

Posted by liuxueyang at 2021-01-28 18:11:18 on Problem 1062
核心代码:

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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator