Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jaehyunp/stanfordacm
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehyunp committed Jun 10, 2016
2 parents 6161380 + 2ad700e commit 462f71f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ HTML version
------------
Requires: [Python 2/3](https://www.python.org/), [enscript](https://www.gnu.org/software/enscript/)

Script for generating the PDF file is `generate_html.py`.
Script for generating the HTML file is `generate_html.py`.
Syntax highlighting is handled solely by enscript, and in order to change the color schemes, either the default options of enscript or `generate_html.py` should be edited accordingly.

Links
Expand Down
19 changes: 16 additions & 3 deletions code/UnionFind.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
//union-find set: the vector/array contains the parent of each node
int find(vector <int>& C, int x){return (C[x]==x) ? x : C[x]=find(C, C[x]);} //C++
int find(int x){return (C[x]==x)?x:C[x]=find(C[x]);} //C
#include <iostream>
#include <vector>
using namespace std;
int find(vector<int> &C, int x) { return (C[x] == x) ? x : C[x] = find(C, C[x]); }
void merge(vector<int> &C, int x, int y) { C[find(C, x)] = find(C, y); }
int main()
{
int n = 5;
vector<int> C(n);
for (int i = 0; i < n; i++) C[i] = i;
merge(C, 0, 2);
merge(C, 1, 0);
merge(C, 3, 4);
for (int i = 0; i < n; i++) cout << i << " " << find(C, i) << endl;
return 0;
}

0 comments on commit 462f71f

Please sign in to comment.