From 4c70db554787d85d42916818a7123f3961d9b2ef Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Fri, 5 Oct 2018 00:33:16 -0700 Subject: [PATCH 01/10] floyd warshall algorithm for finding all pair shortest path in a connected graph --- .../CPP/floyd-warshall algorithm.cpp | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp diff --git a/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp b/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp new file mode 100644 index 00000000..9c0160af --- /dev/null +++ b/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp @@ -0,0 +1,73 @@ +//Floyd-Warshall Algorithm: all pair shortest path +#include +#include +using namespace std; + +#define INF 999999999 + +int main() +{ + int graph[1001][1001],i,j,k,n,m; + cin>>n>>m; //number of vertices and edges respectively + + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + if(i==j) graph[i][j]=0; //Shortest distance between (i,i) is 0 + else + graph[i][j] = INF; //Initializing other distances as infinite + } + + for(i=1;i<=m;i++) + { + int u,v,w; + cin>>u>>v>>w; + graph[u][v] = w; //input graph + graph[v][u] = w; //Shortest distance between (i,j) using atmost one edge + } + + + for(k=1;k<=n;k++) + { + for(int u=1;u<=n;u++) + { + for(int v=1;v<=n;v++) + { + //Shortest distance between (i,j) using atmost k edges + graph[u][v] = min(graph[u][v],graph[u][k]+graph[k][v]); + } + } + } + + //Resulting all pair shortest path in given graph + for(int u=1;u<=n;u++) + { + for(int v=1;v<=n;v++) + { + cout< Date: Sat, 6 Oct 2018 12:44:07 +0530 Subject: [PATCH 02/10] Added whitespaces --- .../CPP/floyd-warshall algorithm.cpp | 44 ++++++++----------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp b/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp index 9c0160af..ecbe3f70 100644 --- a/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp +++ b/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp @@ -5,50 +5,42 @@ using namespace std; #define INF 999999999 -int main() -{ - int graph[1001][1001],i,j,k,n,m; - cin>>n>>m; //number of vertices and edges respectively +int main() { + int graph[1001][1001], i, j, k, n, m; + cin >> n >> m; //number of vertices and edges respectively - for(i=1;i<=n;i++) - { - for(j=1;j<=n;j++) - if(i==j) graph[i][j]=0; //Shortest distance between (i,i) is 0 + for(i = 1; i <= n; i++) { + for(j = 1; j <= n; j++) + if(i == j) graph[i][j] = 0; //Shortest distance between (i,i) is 0 else graph[i][j] = INF; //Initializing other distances as infinite } - for(i=1;i<=m;i++) - { - int u,v,w; - cin>>u>>v>>w; + for(i = 1; i <= m; i++) { + int u, v, w; + cin>> u >> v >> w; graph[u][v] = w; //input graph graph[v][u] = w; //Shortest distance between (i,j) using atmost one edge } - for(k=1;k<=n;k++) - { - for(int u=1;u<=n;u++) - { - for(int v=1;v<=n;v++) - { + for(k = 1; k <= n; k++) { + for(int u = 1; u <= n; u++) { + for(int v = 1;v <= n; v++) { //Shortest distance between (i,j) using atmost k edges - graph[u][v] = min(graph[u][v],graph[u][k]+graph[k][v]); + graph[u][v] = min(graph[u][v], graph[u][k] + graph[k][v]); } } } //Resulting all pair shortest path in given graph - for(int u=1;u<=n;u++) - { - for(int v=1;v<=n;v++) - { - cout< Date: Sat, 6 Oct 2018 12:54:38 +0530 Subject: [PATCH 03/10] Deleted extra trailing whitespaces --- floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp b/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp index ecbe3f70..e3c26655 100644 --- a/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp +++ b/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp @@ -28,7 +28,7 @@ int main() { for(int u = 1; u <= n; u++) { for(int v = 1;v <= n; v++) { //Shortest distance between (i,j) using atmost k edges - graph[u][v] = min(graph[u][v], graph[u][k] + graph[k][v]); + graph[u][v] = min(graph[u][v], graph[u][k] + graph[k][v]); } } } @@ -46,8 +46,8 @@ int main() { /* Input:- -First line contain two space separated integer n and m -where n is the number of vertices and m is the number +First line contain two space separated integer n and m +where n is the number of vertices and m is the number of edges.Next m lines contains three space seprated integers u, v and w which represents that there is an edge between u and v and weight of the edge is w From 57bffc236be0ef468c62b836863a373becd79c29 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Sat, 6 Oct 2018 13:17:16 +0530 Subject: [PATCH 04/10] Updated comments --- .../CPP/floyd-warshall algorithm.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp b/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp index e3c26655..61c71e0d 100644 --- a/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp +++ b/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp @@ -1,4 +1,4 @@ -//Floyd-Warshall Algorithm: all pair shortest path +// Floyd-Warshall Algorithm: all pair shortest path #include #include using namespace std; @@ -7,33 +7,33 @@ using namespace std; int main() { int graph[1001][1001], i, j, k, n, m; - cin >> n >> m; //number of vertices and edges respectively + cin >> n >> m; // number of vertices and edges respectively for(i = 1; i <= n; i++) { for(j = 1; j <= n; j++) - if(i == j) graph[i][j] = 0; //Shortest distance between (i,i) is 0 + if(i == j) graph[i][j] = 0; // Shortest distance between (i,i) is 0 else - graph[i][j] = INF; //Initializing other distances as infinite + graph[i][j] = INF; // Initializing other distances as infinite } for(i = 1; i <= m; i++) { int u, v, w; cin>> u >> v >> w; - graph[u][v] = w; //input graph - graph[v][u] = w; //Shortest distance between (i,j) using atmost one edge + graph[u][v] = w; // input graph + graph[v][u] = w; // Shortest distance between (i,j) using atmost one edge } for(k = 1; k <= n; k++) { for(int u = 1; u <= n; u++) { for(int v = 1;v <= n; v++) { - //Shortest distance between (i,j) using atmost k edges + // Shortest distance between (i,j) using atmost k edges graph[u][v] = min(graph[u][v], graph[u][k] + graph[k][v]); } } } - //Resulting all pair shortest path in given graph + // Resulting all pair shortest path in given graph for(int u = 1; u <= n; u++) { for(int v = 1; v <= n; v++) { cout << graph[u][v] << " "; From c578bd6f9113736c36767c174174348800b1299c Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Sat, 6 Oct 2018 13:28:43 +0530 Subject: [PATCH 05/10] Added whitespace --- floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp b/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp index 61c71e0d..0eaa7206 100644 --- a/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp +++ b/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp @@ -26,7 +26,7 @@ int main() { for(k = 1; k <= n; k++) { for(int u = 1; u <= n; u++) { - for(int v = 1;v <= n; v++) { + for(int v = 1; v <= n; v++) { // Shortest distance between (i,j) using atmost k edges graph[u][v] = min(graph[u][v], graph[u][k] + graph[k][v]); } From 3f7560f0773aab03931ac17a2e003febb6db8fce Mon Sep 17 00:00:00 2001 From: vivekcrux Date: Sat, 6 Oct 2018 13:38:39 +0530 Subject: [PATCH 06/10] renamed file from floyd-warshall algorithm.cpp to floyd_warshall_algorithm.cpp --- ...{floyd-warshall algorithm.cpp => floyd_warshall_algorithm.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename floyd_warshall_algorithm/CPP/{floyd-warshall algorithm.cpp => floyd_warshall_algorithm.cpp} (100%) diff --git a/floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp b/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp similarity index 100% rename from floyd_warshall_algorithm/CPP/floyd-warshall algorithm.cpp rename to floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp From eeed8d3b575d166018edfb7a9d7bf7cd7edfc67b Mon Sep 17 00:00:00 2001 From: vivekcrux Date: Sat, 6 Oct 2018 14:05:30 +0530 Subject: [PATCH 07/10] added input.txt --- .../CPP/floyd_warshall_algorithm.cpp | 1 + floyd_warshall_algorithm/CPP/input.txt | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 floyd_warshall_algorithm/CPP/input.txt diff --git a/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp b/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp index 0eaa7206..7494cc64 100644 --- a/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp +++ b/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp @@ -6,6 +6,7 @@ using namespace std; #define INF 999999999 int main() { + freopen("input.txt", "r", stdin); int graph[1001][1001], i, j, k, n, m; cin >> n >> m; // number of vertices and edges respectively diff --git a/floyd_warshall_algorithm/CPP/input.txt b/floyd_warshall_algorithm/CPP/input.txt new file mode 100644 index 00000000..574ac24c --- /dev/null +++ b/floyd_warshall_algorithm/CPP/input.txt @@ -0,0 +1,10 @@ +6 9 +1 2 1 +1 3 2 +1 4 5 +2 4 5 +2 5 2 +3 4 3 +4 5 1 +4 6 1 +5 6 4 \ No newline at end of file From 1f2b74ab0741c0e50b911daaef43bebae72526c2 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Sun, 7 Oct 2018 01:12:55 +0530 Subject: [PATCH 08/10] graph matrix size fix graph matrix size according to input number of vertices. --- floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp b/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp index 7494cc64..d55b0e94 100644 --- a/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp +++ b/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp @@ -7,9 +7,10 @@ using namespace std; int main() { freopen("input.txt", "r", stdin); - int graph[1001][1001], i, j, k, n, m; + int i, j, k, n, m; cin >> n >> m; // number of vertices and edges respectively - + int graph[n+1][n+1]; + for(i = 1; i <= n; i++) { for(j = 1; j <= n; j++) if(i == j) graph[i][j] = 0; // Shortest distance between (i,i) is 0 From 590cd8e6f5b1472522b542247fe94660eaafc97a Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Sun, 7 Oct 2018 01:22:48 +0530 Subject: [PATCH 09/10] Removed whitespace --- floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp b/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp index d55b0e94..3c21cc6e 100644 --- a/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp +++ b/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp @@ -10,7 +10,7 @@ int main() { int i, j, k, n, m; cin >> n >> m; // number of vertices and edges respectively int graph[n+1][n+1]; - + for(i = 1; i <= n; i++) { for(j = 1; j <= n; j++) if(i == j) graph[i][j] = 0; // Shortest distance between (i,i) is 0 From 85f6af2baeb8803afeea3bd95f547103865ba6fb Mon Sep 17 00:00:00 2001 From: vivekcrux Date: Sun, 7 Oct 2018 01:41:12 +0530 Subject: [PATCH 10/10] fix bus error --- .../CPP/.fuse_hidden0000026400000001 | 66 ++++++++++++++++++ floyd_warshall_algorithm/CPP/a | Bin 0 -> 17064 bytes .../CPP/floyd_warshall_algorithm.cpp | 6 +- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 floyd_warshall_algorithm/CPP/.fuse_hidden0000026400000001 create mode 100644 floyd_warshall_algorithm/CPP/a diff --git a/floyd_warshall_algorithm/CPP/.fuse_hidden0000026400000001 b/floyd_warshall_algorithm/CPP/.fuse_hidden0000026400000001 new file mode 100644 index 00000000..7494cc64 --- /dev/null +++ b/floyd_warshall_algorithm/CPP/.fuse_hidden0000026400000001 @@ -0,0 +1,66 @@ +// Floyd-Warshall Algorithm: all pair shortest path +#include +#include +using namespace std; + +#define INF 999999999 + +int main() { + freopen("input.txt", "r", stdin); + int graph[1001][1001], i, j, k, n, m; + cin >> n >> m; // number of vertices and edges respectively + + for(i = 1; i <= n; i++) { + for(j = 1; j <= n; j++) + if(i == j) graph[i][j] = 0; // Shortest distance between (i,i) is 0 + else + graph[i][j] = INF; // Initializing other distances as infinite + } + + for(i = 1; i <= m; i++) { + int u, v, w; + cin>> u >> v >> w; + graph[u][v] = w; // input graph + graph[v][u] = w; // Shortest distance between (i,j) using atmost one edge + } + + + for(k = 1; k <= n; k++) { + for(int u = 1; u <= n; u++) { + for(int v = 1; v <= n; v++) { + // Shortest distance between (i,j) using atmost k edges + graph[u][v] = min(graph[u][v], graph[u][k] + graph[k][v]); + } + } + } + + // Resulting all pair shortest path in given graph + for(int u = 1; u <= n; u++) { + for(int v = 1; v <= n; v++) { + cout << graph[u][v] << " "; + } + cout << endl; + } + cout << endl; + return 0; +} + +/* +Input:- +First line contain two space separated integer n and m +where n is the number of vertices and m is the number +of edges.Next m lines contains three space seprated integers +u, v and w which represents that there is an edge between u and v +and weight of the edge is w +Sample Input:- +6 9 +1 2 1 +1 3 2 +1 4 5 +2 4 5 +2 5 2 +3 4 3 +4 5 1 +4 6 1 +5 6 4 +*/ diff --git a/floyd_warshall_algorithm/CPP/a b/floyd_warshall_algorithm/CPP/a new file mode 100644 index 0000000000000000000000000000000000000000..056315564a99b54b4f54f4dfb96db8c7482c5288 GIT binary patch literal 17064 zcmeHOe{5UFeLs?x?KCk(IZEdwOH3s3<}5HR#daXqOY$iBIZuh~D3+XhP1R?LqAd=T zsFIJioWZbM*=Y$zwb3?#vlXbZ0)tm%SkM(iR$#Vlcad!rgX*qLwz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QUb`CXq_VakzwYgq#Z59&M^m zl(-L}cr);8PRwpkw@ zlIL$K{g4_YULBpms!KIl|YRV#Jc ziN=~%my+%|3{~|&Qe{XH$?hL;V!hx_M)7_wB?p~EW=KQ^(@r81ZEauU#P*2Dp21wC zKbGwmk-q(da8}&OD9zqPCX1J&La?F3xQUU2E)As|5s`0P1P7H+mc5Q-(sGbT68-k> zOl%-w_xHh7=x>#bQ0bZSGg zAzG>!zI_zYCe;tIR$+f5U`U0b7gR0EtaL__{WUB$p+IXh_UG^GVeKz>5JOMvJL)_8 z^E#>x7@4v^e}`Yu4dnG7OeA^p_Y_cCd$B)%ulMQ&C4J8kasSzl`A+C)Eywc6VuQ@_ zeJ`0X6qD^I8*aab#U2!>sq8h=E% zV3ZSG9saX7Ab~=Pk&l~nT1(Jgl-&Md?H|_uCrXy8pkWR#4te~?wg0#_JnN~D{W&as zH@fTR@4LhLgPGUeZ0`vt#Hc*Z-T) zxczzk)E`zZyGZFGetr!79SU?#Projubrzqa_U4QInbY?^zQ#-bydE200}#Y^N-E2Y z{|gk0*yWP=k*<*a}Vpp^7!O>xnDnoue*L;2hOflHL#tMZf-xl zA8vnP7|OIsv0aLl?p#0f|AfZv&)?6xwEsf&bHJaYK(V<0Bf9<}uAc{%b_i?EYz76Y zUz;;5*#Eu~q6%b76ihOGka1e?%2FdX!u*+cu!! SF_Eg~PbrHJ*idt?|E~cl0SB@G literal 0 HcmV?d00001 diff --git a/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp b/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp index 3c21cc6e..efa74057 100644 --- a/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp +++ b/floyd_warshall_algorithm/CPP/floyd_warshall_algorithm.cpp @@ -1,15 +1,17 @@ // Floyd-Warshall Algorithm: all pair shortest path #include +#include #include using namespace std; #define INF 999999999 +#define MAXN 1001 int main() { freopen("input.txt", "r", stdin); int i, j, k, n, m; cin >> n >> m; // number of vertices and edges respectively - int graph[n+1][n+1]; + int graph[MAXN][MAXN]; for(i = 1; i <= n; i++) { for(j = 1; j <= n; j++) @@ -49,7 +51,7 @@ int main() { /* Input:- First line contain two space separated integer n and m -where n is the number of vertices and m is the number +where n(1 <= n <= 1000) is the number of vertices and m is the number of edges.Next m lines contains three space seprated integers u, v and w which represents that there is an edge between u and v and weight of the edge is w