Add Templates Folder, Union Find
- format.sh
* Fix detection for modified files
* Format templates
Diffstat:
3 files changed, 32 insertions(+), 1 deletions(-)
@@ -266,6 +266,10 @@
if you have any questions.
| 2477 | Medium | [Minimum Fuel Cost to Report to the Capital](Problems/2477.cpp) |
| 2492 | Medium | [Minimum Score of a Path Between Two Cities](Problems/2492.cpp) |
## Templates
* [Union Find](Templates/Union_Find.cpp)
## DNF
| Number | Difficulty | Solution |
@@ -0,0 +1,27 @@
class UnionFind {
int n;
vector<int> root, rank;
public:
UnionFind(int n) : n(n), root(n), rank(n, 1) {
iota(root.begin(), root.end(), 0);
}
int find(int x) {
while (x != root[x]) x = root[x] = root[root[x]];
return x;
}
void join(int x, int y) {
x = find(x), y = find(y);
if (x != y) {
if (rank[x] > rank[y]) swap(x, y);
root[x] = y;
rank[y] += 1;
n--;
}
}
int count() { return n; }
bool connected(int x, int y) { return find(x) == find(y); }
};
@@ -1,7 +1,7 @@
#!/bin/bash
# Format newly added files using clang-format
for i in $(git status | grep Problems | xargs)
for i in $(git status | grep -Eo "(Problems|Templates).*")
do
echo "Formating: $i"
clang-format -i $i