Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Caminho das Pontes
#include <stdio.h> #include <string.h> #define MAXN 1010 int A[MAXN][MAXN], visitado[MAXN], dis[MAXN]; int n, m; int dijkstra() { int i; memset(dis, 0x3f, sizeof(dis)); memset(visitado, 0, sizeof(visitado)); dis[0] = 0; for (;;) { int no = -1; for (i = 0; i < n; i++) if (!visitado[i] && (no == -1 || dis[i] < dis[no])) no = i; if (no == -1) break; visitado[no] = 1; for (i = 0; i < n; i++) if (dis[no] + A[no][i] < dis[i]) dis[i] = dis[no] + A[no][i]; } return dis[n-1]; } int main() { int i; int s, t, b; scanf("%d%d", &n, &m); n += 2; memset(A, 0x3f, sizeof(A)); for (i = 0; i < m; i++) { scanf("%d%d%d", &s, &t, &b); A[s][t] = A[t][s] = b; } printf("%d\n", dijkstra()); return 0; }
run
|
edit
|
history
|
help
0
expm1
c1
hacker
1568-1644 Solar eclipses, make 1617(8) and 1620(12) Lunar eclipses the same as Chinese records
ConvHull
Gauss op
ExceptionWhat
funpointer
File System
Peg Grammar AST Parser Computer Language Interpreter