Posts

Showing posts from October, 2020

New Start Day 10: 09/10/2020 Learning Krukshal

Image
 Krukshal Algorithm It is an algorithm to find the minimum spanning tree of a graph. A tree that includes all the nodes and n-1 edges with minimum overall weight. The way I applied Krukshal's algorithm at start was that I sorted every edge and picked them one by one. If I got an edge where both of the vertices were already added I would discard it. If I got an edge where only one was added then I would add the edge and count the other vertex. If I encountered with an edge where none of the vertices were added I would count both of them and do it until I got all the vertices but it had a flaw. I wasn't concerned if these edges were connected to each other in any way. let's say I could get a graph with nodes connected in pairs and not connected to each other. Now I learned Krukshal using geeks for geeks. Two most important functions that fixed my flaw are explained with the code. Source(https://www.geeksforgeeks.org/kruskals-minimum-spanning-tree-using-stl-in-c/) // C++ progr...

New Start day 9: 08/10/2020 Codechef October Long DDIMMST* (note included)

question (source:https://www.codechef.com/OCT20B/problems/DDIMMST) D-Dimensional MST You are given  N  points in  D -dimensional space. The  i t h  point has  D  coordinates -  x i , 1 , x i , 2 , … , x i , D Consider a weighted undirected complete graph with these  N N  points as its vertices. The weight of the edge between points  i  and  j is  | x i , 1 − x j , 1 | + | x i , 2 − x j , 2 | + … + | x i , D − x j , D | Find the weight of the  maximum spanning tree  of this graph. Input: The first line contains two integers  N , D The  i i -th of the next  N  lines contains a description of the  i i -th point. It has  D  integers:  x i , 1 , x i , 2 , … , x i , D Output: Output a single line which contains a single integer - the Maximum Spanning Tree Weight Constraints 1 ≤ D ≤ 5 1 ≤ N ≤ 200 000 0 ≤ x i , j ≤ 100 000 Subtasks 10 points,  N ≤ 5000 N ≤ 5000 90 points,...