Skip to content

Commit

Permalink
some modification
Browse files Browse the repository at this point in the history
  • Loading branch information
zarif98sjs committed Aug 15, 2021
1 parent ba75f25 commit efd2e39
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 188 deletions.
19 changes: 19 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -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
}
25 changes: 13 additions & 12 deletions Algorithm/02 DFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,23 @@ inline void optimizeIO()
const int nmax = 2e5+7;
const LL LINF = 1e17;

string to_str(LL x)
{
stringstream ss;
ss<<x;
return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

vector<int>adj[nmax];
vector<bool>vis(nmax,false);
vector<int>dist(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;
Expand Down
49 changes: 9 additions & 40 deletions Algorithm/07 Prim's MST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,6 @@ using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>
using indexed_set = tree<
TIn, null_type, less<TIn>,
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);
Expand All @@ -52,49 +33,37 @@ inline void optimizeIO()
const int nmax = 1e3+7;
const LL LINF = 1e17;

string to_str(LL x)
{
stringstream ss;
ss<<x;
return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

int nodes,edges;

vector<PII>adj[nmax];

LL MinST(int src = 1) /** n vertices , 1 based indexing **/
{
priority_queue< PII,vector<PII>,greater <PII> >PQ;
vector<bool> inMinST(nmax, false);
vector<PII> parent(nmax,{-1,0});
vector<bool>inMinST(nmax, false);
vector<PII>parent(nmax,{-1,0});
vector<int>min_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())
{
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 && weight<min_d[next]) /** For maximum spanning tree , weight>max_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]);
}
}
}
Expand Down
32 changes: 1 addition & 31 deletions Algorithm/08 Kruskal's MST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,6 @@ using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>
using indexed_set = tree<
TIn, null_type, less<TIn>,
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);
Expand All @@ -52,17 +33,6 @@ inline void optimizeIO()
const int nmax = 1e3+7;
const LL LINF = 1e17;

string to_str(LL x)
{
stringstream ss;
ss<<x;
return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

struct Edge {
int src, dest, weight;
Expand Down Expand Up @@ -102,7 +72,7 @@ class DisjointSet
if (parent[k] == k)
return k;

return parent[k] =Find(parent[k]);
return parent[k] = Find(parent[k]);
}

void Union(int a, int b)
Expand Down
31 changes: 0 additions & 31 deletions Algorithm/38 Subtree Size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,6 @@ using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>
using indexed_set = tree<
TIn, null_type, less<TIn>,
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);
Expand All @@ -49,18 +30,6 @@ inline void optimizeIO()
const int nmax = 2e5+7;
const LL LINF = 1e17;

string to_str(LL x)
{
stringstream ss;
ss<<x;
return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

vector<int>adj[nmax];
int sub[nmax]; /** subtree size **/

Expand Down
20 changes: 0 additions & 20 deletions Algorithm/40 Cycle Check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,6 @@ using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>
using indexed_set = tree<
TIn, null_type, less<TIn>,
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);
Expand Down
27 changes: 0 additions & 27 deletions Algorithm/41 Cycle Check Directed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,6 @@ using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>
using indexed_set = tree<
TIn, null_type, less<TIn>,
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);
Expand All @@ -59,13 +39,6 @@ inline void optimizeIO()
const int nmax = 2e5+7;
const LL LINF = 1e17;

string to_str(LL x)
{
stringstream ss;
ss<<x;
return ss.str();
}

vector<int>adj[nmax];
vector<int>col(nmax,0);

Expand Down
27 changes: 0 additions & 27 deletions Algorithm/41.2 Cycle Check Directed 2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,6 @@ using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>
using indexed_set = tree<
TIn, null_type, less<TIn>,
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);
Expand All @@ -69,13 +49,6 @@ inline void optimizeIO()
const int nmax = 2e5+7;
const LL LINF = 1e17;

string to_str(LL x)
{
stringstream ss;
ss<<x;
return ss.str();
}

vector<vector<int>>adj;

vector<bool>vis;
Expand Down

0 comments on commit efd2e39

Please sign in to comment.