From efd2e396247fbdc662b1efd473ec66273b8d003e Mon Sep 17 00:00:00 2001 From: Zarif Date: Sun, 15 Aug 2021 20:07:41 +0600 Subject: [PATCH] some modification --- .vscode/c_cpp_properties.json | 19 +++++++++ Algorithm/02 DFS.cpp | 25 ++++++------ Algorithm/07 Prim's MST.cpp | 49 +++++------------------ Algorithm/08 Kruskal's MST.cpp | 32 +-------------- Algorithm/38 Subtree Size.cpp | 31 -------------- Algorithm/40 Cycle Check.cpp | 20 --------- Algorithm/41 Cycle Check Directed.cpp | 27 ------------- Algorithm/41.2 Cycle Check Directed 2.cpp | 27 ------------- 8 files changed, 42 insertions(+), 188 deletions(-) create mode 100644 .vscode/c_cpp_properties.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..50d7bb7 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,19 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "windowsSdkVersion": "10.0.16299.0", + "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe", + "intelliSenseMode": "windows-msvc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/Algorithm/02 DFS.cpp b/Algorithm/02 DFS.cpp index 319f7dd..8dd1f00 100644 --- a/Algorithm/02 DFS.cpp +++ b/Algorithm/02 DFS.cpp @@ -49,22 +49,23 @@ inline void optimizeIO() const int nmax = 2e5+7; const LL LINF = 1e17; -string to_str(LL x) -{ - stringstream ss; - ss<adj[nmax]; vectorvis(nmax,false); vectordist(nmax,0); +/** + * + * For tree, it is sufficient to only keep track of parent + * + * void dfs(int u,int p) + * { + * for(int v:adj[u]) + * if(v != p) + * dfs(v,u); + * } + * + **/ + void dfs(int u) { vis[u] = true; diff --git a/Algorithm/07 Prim's MST.cpp b/Algorithm/07 Prim's MST.cpp index a4dcc79..65fedd5 100644 --- a/Algorithm/07 Prim's MST.cpp +++ b/Algorithm/07 Prim's MST.cpp @@ -24,25 +24,6 @@ using namespace std; #define ALL(x) (x).begin(), (x).end() #define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl -#include -#include -using namespace __gnu_pbds; - -template -using indexed_set = tree< - TIn, null_type, less, - rb_tree_tag, tree_order_statistics_node_update>; - -/* -PBDS -------------------------------------------------- -1) insert(value) -2) erase(value) -3) order_of_key(value) // 0 based indexing -4) *find_by_order(position) // 0 based indexing - -*/ - inline void optimizeIO() { ios_base::sync_with_stdio(false); @@ -52,18 +33,6 @@ inline void optimizeIO() const int nmax = 1e3+7; const LL LINF = 1e17; -string to_str(LL x) -{ - stringstream ss; - ss<adj[nmax]; @@ -71,11 +40,11 @@ vectoradj[nmax]; LL MinST(int src = 1) /** n vertices , 1 based indexing **/ { priority_queue< PII,vector,greater >PQ; - vector inMinST(nmax, false); - vector parent(nmax,{-1,0}); + vectorinMinST(nmax, false); + vectorparent(nmax,{-1,0}); vectormin_d(nmax,INF); /** For maximum spanning tree , USE max_d(nmax,0) **/ - min_d[src]=0; + min_d[src] = 0; PQ.push({0,src}); while(!PQ.empty()) @@ -83,18 +52,18 @@ LL MinST(int src = 1) /** n vertices , 1 based indexing **/ int now=PQ.top().S; PQ.pop(); - inMinST[now]=true; + inMinST[now] = true; for(auto x:adj[now]) { - int next=x.F; - int weight=x.S; + int next = x.F; + int weight = x.S; - if(inMinST[next]==false && weightmax_d[next] **/ + if(inMinST[next] == false && weight < min_d[next]) /** For maximum spanning tree , weight>max_d[next] **/ { - min_d[next]=weight; + min_d[next] = weight; PQ.push(MP(min_d[next],next)); - parent[next]=MP(now,min_d[next]); + parent[next] = MP(now,min_d[next]); } } } diff --git a/Algorithm/08 Kruskal's MST.cpp b/Algorithm/08 Kruskal's MST.cpp index bdf98cd..f1c1a83 100644 --- a/Algorithm/08 Kruskal's MST.cpp +++ b/Algorithm/08 Kruskal's MST.cpp @@ -24,25 +24,6 @@ using namespace std; #define ALL(x) (x).begin(), (x).end() #define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl -#include -#include -using namespace __gnu_pbds; - -template -using indexed_set = tree< - TIn, null_type, less, - rb_tree_tag, tree_order_statistics_node_update>; - -/* -PBDS -------------------------------------------------- -1) insert(value) -2) erase(value) -3) order_of_key(value) // 0 based indexing -4) *find_by_order(position) // 0 based indexing - -*/ - inline void optimizeIO() { ios_base::sync_with_stdio(false); @@ -52,17 +33,6 @@ inline void optimizeIO() const int nmax = 1e3+7; const LL LINF = 1e17; -string to_str(LL x) -{ - stringstream ss; - ss<