Algorithms on graphs week 5 Connecting points solution#54
Open
unknown-08 wants to merge 1 commit intothakur24:masterfrom
unknown-08:unknown-08-patch-1
Open
Algorithms on graphs week 5 Connecting points solution#54unknown-08 wants to merge 1 commit intothakur24:masterfrom unknown-08:unknown-08-patch-1
unknown-08 wants to merge 1 commit intothakur24:masterfrom
unknown-08:unknown-08-patch-1
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define mod 1000000007
using namespace std;
bool sortbysec(const pair<int,int> &a,
const pair<int,int> &b)
{
return (a.second < b.second);
}
struct hash_pair {
template <class T1, class T2>size_t operator()(const pair<T1, T2>& p) const
{
auto hash1 = hash{}(p.first);
auto hash2 = hash{}(p.second);
return hash1 ^ hash2;
}
};
bool sortbyth(const tuple<int, int, double>& a,const tuple<int, int, double>& b)
{
return (get<2>(a) < get<2>(b));
}
struct edge{
int a,b;
double cost;
};
double dis(double x1,double y1,double x2,double y2)
{
double d=sqrt((x1-x2)(x1-x2)+(y1-y2)(y1-y2));
return d;
}
class DisjSet {
int *rank, *parent, n;
public:
DisjSet(int n)
{
rank = new int[n];
parent = new int[n];
this->n = n;
makeSet();
}
};
int main()
{
int n,i,j;
cin>>n;
double x[n],y[n];
for(i=0;i<n;i++) cin>>x[i]>>y[i];
vector<tuple<int,int,double>>v; // vector tuple used to store the distance between the given points
DisjSet obj(n+1);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
double d=dis(x[i],y[i],x[j],y[j]); // calculating the distance between two points
v.pb(make_tuple(i,j,d)); // storing distance between point i and j in the vector
}
}
}