Topics are linked below:
https://www.patest.cn/contests/gplt/L2-001
This problem is a shortest path (Dijkstra algorithm), the template slightly modified on the line, that is, another record of the route number of the array (that is, when the length of the road and the next need to judge the
The lengths of the nodes are equal when the route is added) and an array of the total number of cars that record each node on the shortest path basis, and then OK, the code is as follows:
#include <cstdio> #include <iostream> #include <cstring> #define MAXN 1000000000 using namespace std;
int ma[505][505], dis[505], pre[505], car[505], totcar[505], pathnum[505];
BOOL vis[505];
void spath (int v0, int n) {int V, W, K, Minn;
Vis[v0] = 1;
Dis[v0] = 0;
Totcar[v0] = Car[v0];
Pathnum[v0] = 1;
for (v=0; v<n; v++) {Dis[v] = Ma[v0][v];
if (ma[v0][v]! = MAXN && v!=v0) {pre[v] = V0;
TOTCAR[V] = Car[v0] + car[v];
PATHNUM[V] = 1;
}} for (v=1; v<n; v++) {minn = MAXN;
K=v0;
for (w=0; w<n; w++) {if (!vis[w]&&dis[w]<minn) {k=w;
MINN=DIS[W];
}} vis[k]=1;
for (w=0; w<n; w++) {if (!vis[w]) {if (minn+ma[k][w]<dis[w]) {PathnuM[W] = pathnum[k];
DIS[W]=MINN+MA[K][W];
Pre[w]=k;
TOTCAR[W] = totcar[k]+car[w];
} else if (minn+ma[k][w] = = Dis[w]) {pathnum[w] + = pathnum[k]; if (Totcar[w] < totcar[k]+car[w]) {Totcar[w] = totcar[k]+car[
W];
PRE[W] = k;
}}}}}} void Create (int n, int m) {int A, B, C;
for (int i=0, i<n; i++) for (int j=0; j<n; j + +) ma[i][j] = MAXN;
for (int i=1; i<=m; i++) {cin >> A >> B >> C;
MA[A][B] = ma[b][a] = C;
}} int main () {int n, m, S, D;
CIN >> N >> m >> s >> D;
for (int i=0; i<n; i++) cin >> Car[i];
Create (n, m);
Spath (s, N);
int i=0,, path[505], Cur=d; while (cUr!=s) {path[i++] = cur;
cur = pre[cur];
} Path[i] = s;
printf ("%d%d\n", Pathnum[d], totcar[d]);
for (int j=i; j>0; j--) printf ("%d", path[j]);
printf ("%d\n", path[0]);
return 0;
}