Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Takanori MAEHARA
committed
Jun 15, 2016
1 parent
d856cc1
commit fdc02eb
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <cstdio> | ||
#include <algorithm> | ||
#include <functional> | ||
|
||
using namespace std; | ||
|
||
#define fst first | ||
#define snd second | ||
#define all(c) ((c).begin()), ((c).end()) | ||
#define TEST(s) if (!(s)) { cout << __LINE__ << " " << #s << endl; exit(-1); } | ||
|
||
// specify operator == | ||
template <class T, class F> | ||
void equivalence(vector<T> x, F eq) { | ||
vector<int> parent(x.size()); | ||
for (int i = ; i < x.size(); ++i) { | ||
parent[i] = i; | ||
for (int j = 0; j < i; ++j) { | ||
parent[j] = parent[parent[j]]; | ||
if (eq(x[i], x[j])) parent[parent[parent[j]]] = i; | ||
} | ||
} | ||
for (int i = 0; i < x.size(); ++i) parent[i] = parent[parent[i]]; | ||
|
||
for (int i = 0; i < parent.size(); ++i) | ||
printf("%d %d \n", x[i], parent[i]); | ||
} | ||
|
||
int main() { | ||
vector<int> x = {3,1,4,1,5,9,2,6,5,3,5,8,9}; | ||
equivalence(x, [&](int a, int b) { return a == b; }); | ||
} |