This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
--- Representational Code Only: Not to compile | |
--- Aditya Jain ------------------------------ | |
--- IIT INDORE ------------------------------- | |
*/ | |
// libraries | |
#include <semaphore.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adjacency Matrix Representation | |
*/ | |
// undirected dense graph (with lesser nodes eg N = 1e3) | |
int adj_matrix[N][N]; | |
int main(){ | |
int num_nodes, num_edges; | |
cin >> num_nodes >> num_edges; | |
for(int i = 0, u, v; i < num_edges; ++i){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adjacency List in Vector | |
*/ | |
vector <vector <int> > adj_list; | |
int main(){ | |
int num_nodes, num_edges; | |
cin >> num_nodes >> num_edges; | |
adj_list.resize(num_nodes+1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool vis[N]; // mark nodes which we have already visited | |
vector <vector <int> > adj; // adjacency list vectors | |
void dfs(int node){ | |
if(vis[node]) // if already visited, return | |
return; | |
vis[node] = 1; // mark this node as visited | |
// do something | |
// example | |
cout << "Reached node: " << node << endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector <vector <int> > adj; // adjacency list vectors | |
void dfs(int i, int par){ | |
// set parent of i as the value passed in par | |
parent[i] = par; | |
if(par == -1) // means i is root | |
level[i] = 0; | |
else // otherwise | |
level[i] = level[parent[i]]+1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector < vector <int> > adj; | |
int attending[N]; | |
void dfs(int i, int par){ | |
int sm = 0; | |
for(auto j: adj[i]){ | |
if(j == par) | |
continue; | |
dfs(j, i); // call dfs on child node to compute its answer | |
sm += attending[j]; // add to the sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cin >> x >> u; // input id for newly added node and its to-be manager | |
// lets assume we have the parent array created for us already | |
// lets add parent for newly added node x | |
parent[x] = u; | |
// add 1 to all nodes on path towards root | |
int curr = x; | |
while(curr != -1){ | |
attending[curr]++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# START NAME SERVER AS: | |
$ pyro4-ns --host 172.22.134.7 --port 9090 | |
# SERVER CODE | |
import Pyro4 | |
@Pyro4.expose | |
class RemoteClass: | |
def __init__(self, x): | |
print("initialising remote object") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## This keeps adding 90 to the idd value in Server | |
## Never name the method (for setter and value) same as the attr name, will result in recursive calls (seg fault) | |
# SERVER | |
import Pyro4 | |
@Pyro4.expose | |
class RemoteClass: | |
def __init__(self, x): | |
print("initialising remote object") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <string> | |
struct Shape | |
{ | |
virtual std::string str() const = 0; | |
}; | |
struct Circle : Shape |
OlderNewer