Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Faster Floyd-Warshall
- * approximately 800 ms for 1000x1000 matrix
- */
- public static void FloydWarshall(int[][] M) {
- int N = M.length;
- for (int v = 0; v < N; v++) {
- for (int f = 0; f < N; f++) {
- for (int t = 0; t < N; t++) {
- M[f][t] = Math.min(M[f][t], M[f][v] + M[v][t]);
- }
- }
- }
- }
- /*
- * Slower for some reason
- * approximately 2100 ms for 1000x1000 matrix
- */
- public static void OFloydWarshall(int[][] M) {
- int N = M.length;
- int now, chk;
- for (int via = 0; via < N; via++) {
- for (int van = 0; van < N; van++) {
- for (int naar = 0; naar < N; naar++) {
- now = M[van][naar];
- chk = M[van][via] + M[via][naar];
- if (chk < now) {
- M[van][naar] = chk;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement