Skip to content

Instantly share code, notes, and snippets.

View 08vivek08's full-sized avatar

Vivekanand 08vivek08

  • Maharaja Agrasen Institute Of Technology
View GitHub Profile
#include <iostream>
using namespace std;
int partition (int arr[], int low, int high)
{
int pivot=low+rand()%(high-low+1);
swap(arr[pivot],arr[high]);
int i=low;
for(int j=low;j<high;j++){
if(arr[j]<arr[high]){
@08vivek08
08vivek08 / bridges.cpp
Created June 4, 2021 12:57
finding bridges in graph in O(n+m)
// finding bridges in graph in O(n+m)
// https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737
#include <bits/stdc++.h>
using namespace std;
int timer;
void dfs(int s,int par,vector<int>adj[],vector<bool>&vis,vector<int>&tin,vector<int>&low,vector<pair<int,int>>&ans){
vis[s]=1;
tin[s]=low[s]=++timer;
// author: 08vivek08
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9 + 7;
struct segment_tree
// // Binary Indexed Tree or Fenwick Tree
// // 1 based indexing of array
// #include <bits/stdc++.h>
// using namespace std;
// int sum(int k, int tree[]){
// int s=0;
// while(k>=1){
// s+=tree[k];
// k-=k&-k;
// Directed Acyclic GRAPH
// counting number of paths
// paths (x) denote the number of paths from node a to node x . As a base case paths(a)=1
// vertices start from 1 onwards
#include <bits/stdc++.h>
using namespace std;
class Graph{
int vertices;
vector<int>*adj;
// Kruskal's algorithm to find minimum spanning tree
// O(mlog(m)) time complexity
// vertices start from 1 onwards
#include <bits/stdc++.h>
using namespace std;
const int INF=1e7;
class Graph{
int v,e;
vector<tuple<int,int,int>>edges;
#include <bits/stdc++.h>
using namespace std;
const int Max_char=26;
struct trie{
trie *child[Max_char];
bool isendofword;
};
trie *getnode(){
trie *p=new trie;
// Directed Acyclic GRAPH
// Topological sort
// vertices start from 1 onwards
#include <bits/stdc++.h>
using namespace std;
class Graph{
int vertices;
vector<int>*adj;
bool cycle=false;
// Bellman ford on weighted GRAPH
// O(n*m) time complexity
// GRAPH's edge list representation
// vertices start from 1 onwards
// can detect negative cycle in graph
#include <bits/stdc++.h>
using namespace std;
const int INF=1e7;
int main() {
// DIJKSTRA on weighted GRAPH
// O(n+mlog(m)) time complexity
// vertices start from 1 onwards
// can't work in case of negative edges
#include <bits/stdc++.h>
using namespace std;
const int INF=1e7;
class Graph{
int vertices;