#include<stdio.h>
#include<math.h>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <cstring> 
using namespace std;



// R1 source, R2 destination,R3 weight
void initMSTEdgeList(int *R1 , int *R2 , int *R3, int *indexArray , int *destinationVertexArray, int *weightArray, int vertices)
{
	for(int v = indexArray[0] ; v < indexArray[1] ; v++)
	{
		// update weight of adjacent vertices of vertex 0. -1 bcz counting at r2 starts from 1 i.e at index 0 vertex 1 is placed.
		// So correspondingly for R3.
		R3[destinationVertexArray[v]-1] = weightArray[v];
	}	

	for(int i = 0;i< vertices-1;i++)
	{
		R2[i] = i+1;
		R1[i] = 0;
	}
}

void initializeGraph(int *indexArray , int *destinationVertexArray , int *weightArray, int edges)
{

	
	int u = 1,v,w;
	int count = 0;
	int prev = 1;
    for(int i = 0 ; i < edges ; i++) 
	{
	   prev = u;
       	   cin >>u>>v>>w;
	   if(prev == u)
	   {
			count++;
	   }	
	   else
	   {
		   indexArray[prev] = count + indexArray[prev-1];
		   count = 1;
	   }	
	   destinationVertexArray[i] = v-1;
	   weightArray[i] = w;
    }

}


void printArray(char name,int *a  , int size)
{
    printf("%c: ",name);
    for(int i = 0; i < size ; i++)
        printf("%d\t",a[i]);
    printf("\n");
}


void updateMSTList(int startIndex,int endIndex, int *nearestVertex, int *destinationVertexArray,int *weightArray,int *R1,int *R2,int *R3)
{
	
	for(int i = startIndex; i <= endIndex;i++)
	{	
		if(destinationVertexArray[i] != 0)
		{	
			if(R2[destinationVertexArray[i]-1] != 0)
			{	// -1 bcz the r2 & r3 counting begins from 1.// update the edge and the source vertex.
				if(R3[destinationVertexArray[i]-1] > weightArray[i] )
				{		
					R3[destinationVertexArray[i]-1] = weightArray[i];
					R1[destinationVertexArray[i]-1] = *nearestVertex;
				}
			}
		}
	}
}

void findNearestVertex(int *R1, int *R2 , int *R3, int *nearest_vertex,int vertices)
{

	int *min = (int *)malloc(sizeof(int));
	memset(min,1,sizeof(int));	

	for(int i = 0; i < vertices-1 ; i++)
	{
		if(R3[i] < (*min) && R2[i] != 0)
		{
			 *min = R3[i];
			*nearest_vertex = i+1;			
		}		
	}
	R2[(*nearest_vertex)-1] = 0;
}



int main()
{
	// graph representatioon arrays
	int *indexArray;
	int *weightArray;
	int *destinationVertexArray;


	// MST Edge list
	int *R1;
	int *R2;
	int *R3;
	int *nearestVertex;
   	

	
	int edges,vertices;
	cin>>vertices>>edges;
	edges = edges/2;	
	
	// iteration indexes for updation
	int startIndex, endIndex;
	
	// allocate memory to compact adjacency list

	indexArray = (int *)malloc(vertices * sizeof(int));
 	weightArray = (int *)malloc(2 * edges * sizeof(int));
    destinationVertexArray = (int *)malloc(2 * edges * sizeof(int));
	nearestVertex = (int *)malloc(sizeof(int));
	
	memset(indexArray,0,vertices * sizeof(int));
	memset(weightArray,0,2 * edges * sizeof(int));
	memset(destinationVertexArray,0,2 * edges * sizeof(int));
	*nearestVertex = 0;
	
	R1 = (int *)malloc((vertices-1) * sizeof(int));
	R2 = (int *)malloc((vertices-1) * sizeof(int));
	R3 = (int *)malloc((vertices-1) * sizeof(int));
	memset(R3,1,(vertices-1)*sizeof(int));
	
	initializeGraph(indexArray,destinationVertexArray,weightArray,2*edges);
	
	initMSTEdgeList(R1,R2,R3,indexArray,destinationVertexArray,weightArray,vertices);	


	
		cudaEvent_t start, stop;
        float time;
        cudaEventCreate(&start);
        cudaEventCreate(&stop);
        cudaEventRecord( start, 0 );
	
	// kernel launch
	for(int v = 0 ; v < vertices-2; v++)
	{
		findNearestVertex(R1, R2, R3, nearestVertex,vertices);

		startIndex = indexArray[*nearestVertex];
		if(*(nearestVertex) == vertices-1)
        		endIndex = 2*edges-1;
	    	else
        		endIndex = indexArray[*nearestVertex+1]-1;

		updateMSTList(startIndex, endIndex , nearestVertex, destinationVertexArray, weightArray, R1, R2, R3);
		
	}

        printf("u\tv\tw\n");
		long cost = 0;
		cudaEventRecord( stop, 0 );
        cudaEventSynchronize( stop );
        cudaEventElapsedTime( &time, start, stop );
        cudaEventDestroy( start );
        cudaEventDestroy( stop );

        for(int i = 0; i < vertices-1;i++)
        {
       		 printf("%d\t%d\t%d\t\n",R1[i]+1,i+2,R3[i]);
		 cost = cost + R3[i];
        }
		cout<<"\ncost:"<<cost;
 		printf("\nTime: %fms\n",time);		
}
   

	.file	"tmpxft_002322d3_00000000-6_SerialPrim.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3774:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3774:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z15initMSTEdgeListPiS_S_S_S_S_i
	.type	_Z15initMSTEdgeListPiS_S_S_S_S_i, @function
_Z15initMSTEdgeListPiS_S_S_S_S_i:
.LFB3766:
	.cfi_startproc
	endbr64
	movslq	(%rcx), %rax
.L3:
	cmpl	%eax, 4(%rcx)
	jle	.L8
	movl	(%r9,%rax,4), %r11d
	movslq	(%r8,%rax,4), %r10
	incq	%rax
	movl	%r11d, -4(%rdx,%r10,4)
	jmp	.L3
.L8:
	movl	8(%rsp), %edx
	xorl	%eax, %eax
	decl	%edx
.L5:
	cmpl	%eax, %edx
	jle	.L9
	leal	1(%rax), %ecx
	movl	%ecx, (%rsi,%rax,4)
	xorl	%ecx, %ecx
	movl	%ecx, (%rdi,%rax,4)
	incq	%rax
	jmp	.L5
.L9:
	ret
	.cfi_endproc
.LFE3766:
	.size	_Z15initMSTEdgeListPiS_S_S_S_S_i, .-_Z15initMSTEdgeListPiS_S_S_S_S_i
	.globl	_Z15initializeGraphPiS_S_i
	.type	_Z15initializeGraphPiS_S_i, @function
_Z15initializeGraphPiS_S_i:
.LFB3767:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%ecx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	movl	$1, 28(%rsp)
.L11:
	cmpl	%ebp, %r13d
	jle	.L17
	leaq	28(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	movslq	28(%rsp), %r12
	leaq	_ZSt3cin(%rip), %rdi
	call	_ZNSirsERi@PLT
	leaq	32(%rsp), %rsi
	movq	%rax, %rdi
	call	_ZNSirsERi@PLT
	leaq	36(%rsp), %rsi
	movq	%rax, %rdi
	call	_ZNSirsERi@PLT
	cmpl	%r12d, 28(%rsp)
	movq	8(%rsp), %rdx
	jne	.L12
	incl	%ebx
	jmp	.L13
.L12:
	addl	-4(%r15,%r12,4), %ebx
	movl	%ebx, (%r15,%r12,4)
	movl	$1, %ebx
.L13:
	movl	32(%rsp), %eax
	decl	%eax
	movl	%eax, (%r14,%rbp,4)
	movl	36(%rsp), %eax
	movl	%eax, (%rdx,%rbp,4)
	incq	%rbp
	jmp	.L11
.L17:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3767:
	.size	_Z15initializeGraphPiS_S_i, .-_Z15initializeGraphPiS_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%c: "
.LC1:
	.string	"%d\t"
.LC2:
	.string	"\n"
	.text
	.globl	_Z10printArraycPii
	.type	_Z10printArraycPii, @function
_Z10printArraycPii:
.LFB3768:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	xorl	%eax, %eax
	leaq	.LC1(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	leaq	.LC0(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%edx, %ebp
	movsbl	%dil, %edx
	movl	$2, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 48
	call	__printf_chk@PLT
.L19:
	cmpl	%ebx, %ebp
	jle	.L22
	movl	(%r12,%rbx,4), %edx
	movq	%r13, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbx
	call	__printf_chk@PLT
	jmp	.L19
.L22:
	popq	%rdx
	.cfi_def_cfa_offset 40
	leaq	.LC2(%rip), %rsi
	popq	%rbx
	.cfi_def_cfa_offset 32
	movl	$2, %edi
	popq	%rbp
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE3768:
	.size	_Z10printArraycPii, .-_Z10printArraycPii
	.globl	_Z13updateMSTListiiPiS_S_S_S_S_
	.type	_Z13updateMSTListiiPiS_S_S_S_S_, @function
_Z13updateMSTListiiPiS_S_S_S_S_:
.LFB3769:
	.cfi_startproc
	endbr64
	movq	8(%rsp), %r11
	movslq	%edi, %rax
	movq	%rdx, %r10
	movl	%esi, %edi
.L24:
	cmpl	%eax, %edi
	jl	.L30
	movslq	(%rcx,%rax,4), %rdx
	testl	%edx, %edx
	je	.L25
	salq	$2, %rdx
	cmpl	$0, -4(%r11,%rdx)
	leaq	-4(%rdx), %rsi
	je	.L25
	addq	16(%rsp), %rsi
	movq	%rsi, %rdx
	movl	(%r8,%rax,4), %esi
	cmpl	%esi, (%rdx)
	jle	.L25
	movl	%esi, (%rdx)
	movl	(%r10), %esi
	movslq	(%rcx,%rax,4), %rdx
	movl	%esi, -4(%r9,%rdx,4)
.L25:
	incq	%rax
	jmp	.L24
.L30:
	ret
	.cfi_endproc
.LFE3769:
	.size	_Z13updateMSTListiiPiS_S_S_S_S_, .-_Z13updateMSTListiiPiS_S_S_S_S_
	.globl	_Z17findNearestVertexPiS_S_S_i
	.type	_Z17findNearestVertexPiS_S_S_i, @function
_Z17findNearestVertexPiS_S_S_i:
.LFB3770:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%r8d, %ebx
	pushq	%rdi
	.cfi_def_cfa_offset 48
	movl	$4, %edi
	decl	%ebx
	call	malloc@PLT
	xorl	%edx, %edx
	movl	$16843009, (%rax)
.L32:
	cmpl	%edx, %ebx
	jle	.L36
	movl	0(%r13,%rdx,4), %ecx
	cmpl	(%rax), %ecx
	jge	.L33
	cmpl	$0, 0(%rbp,%rdx,4)
	je	.L33
	movl	%ecx, (%rax)
	leal	1(%rdx), %ecx
	movl	%ecx, (%r12)
.L33:
	incq	%rdx
	jmp	.L32
.L36:
	movslq	(%r12), %rax
	xorl	%edx, %edx
	movl	%edx, -4(%rbp,%rax,4)
	popq	%rcx
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3770:
	.size	_Z17findNearestVertexPiS_S_S_i, .-_Z17findNearestVertexPiS_S_S_i
	.section	.rodata.str1.1
.LC3:
	.string	"u\tv\tw\n"
.LC4:
	.string	"%d\t%d\t%d\t\n"
.LC5:
	.string	"\ncost:"
.LC6:
	.string	"\nTime: %fms\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3771:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	_ZSt3cin(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	leaq	48(%rsp), %rsi
	call	_ZNSirsERi@PLT
	leaq	44(%rsp), %rsi
	movq	%rax, %rdi
	call	_ZNSirsERi@PLT
	movl	44(%rsp), %eax
	movl	$2, %ecx
	movslq	48(%rsp), %rbx
	cltd
	salq	$2, %rbx
	idivl	%ecx
	movq	%rbx, %rdi
	movl	%eax, %ebp
	movl	%eax, 44(%rsp)
	call	malloc@PLT
	addl	%ebp, %ebp
	movq	%rax, %r12
	movslq	%ebp, %rax
	leaq	0(,%rax,4), %r13
	movq	%r13, %rdi
	call	malloc@PLT
	movq	%r13, %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movl	$4, %edi
	movq	%rax, 24(%rsp)
	call	malloc@PLT
	movq	%rbx, %rcx
	movq	%rbx, %rdx
	xorl	%esi, %esi
	movq	%r12, %rdi
	movq	%rax, %r14
	call	__memset_chk@PLT
	movq	16(%rsp), %rdi
	movq	%r13, %rcx
	movq	%r13, %rdx
	xorl	%esi, %esi
	call	__memset_chk@PLT
	movq	24(%rsp), %rdi
	movq	%r13, %rdx
	xorl	%esi, %esi
	movq	%r13, %rcx
	call	__memset_chk@PLT
	xorl	%ecx, %ecx
	leaq	-4(%rbx), %rax
	movl	%ecx, (%r14)
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, %r13
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, %r15
	call	malloc@PLT
	movq	8(%rsp), %rcx
	movl	$1, %esi
	movq	%rax, %rdi
	movq	%rax, %rbx
	movq	%rcx, %rdx
	call	__memset_chk@PLT
	movq	24(%rsp), %rsi
	movl	%ebp, %ecx
	movq	%r12, %rdi
	movq	16(%rsp), %rdx
	xorl	%ebp, %ebp
	call	_Z15initializeGraphPiS_S_i
	movq	%r12, %rcx
	movq	%rbx, %rdx
	movq	%r13, %rdi
	pushq	%rsi
	.cfi_def_cfa_offset 152
	movl	56(%rsp), %eax
	movq	%r15, %rsi
	pushq	%rax
	.cfi_def_cfa_offset 160
	movq	32(%rsp), %r9
	movq	40(%rsp), %r8
	call	_Z15initMSTEdgeListPiS_S_S_S_S_i
	popq	%rdi
	.cfi_def_cfa_offset 152
	popq	%r8
	.cfi_def_cfa_offset 144
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	64(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
.L38:
	movl	48(%rsp), %r8d
	leal	-2(%r8), %eax
	cmpl	%ebp, %eax
	jle	.L46
	movq	%r14, %rcx
	movq	%rbx, %rdx
	movq	%r13, %rdi
	movq	%r15, %rsi
	movl	%r8d, 8(%rsp)
	call	_Z17findNearestVertexPiS_S_S_i
	movl	8(%rsp), %r8d
	movslq	(%r14), %rdx
	decl	%r8d
	movl	(%r12,%rdx,4), %edi
	leaq	0(,%rdx,4), %rcx
	cmpl	%r8d, %edx
	jne	.L39
	movl	44(%rsp), %eax
	leal	-1(%rax,%rax), %esi
	jmp	.L40
.L39:
	movl	4(%r12,%rcx), %esi
	decl	%esi
.L40:
	pushq	%rbx
	.cfi_def_cfa_offset 152
	movq	%r14, %rdx
	movq	%r13, %r9
	incl	%ebp
	pushq	%r15
	.cfi_def_cfa_offset 160
	movq	32(%rsp), %r8
	movq	40(%rsp), %rcx
	call	_Z13updateMSTListiiPiS_S_S_S_S_
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
	jmp	.L38
.L46:
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	call	__printf_chk@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	xorl	%r12d, %r12d
	leaq	.LC4(%rip), %r14
	call	cudaEventRecord@PLT
	movq	64(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rsi
	leaq	52(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	56(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	64(%rsp), %rdi
	call	cudaEventDestroy@PLT
.L42:
	movl	48(%rsp), %eax
	decl	%eax
	cmpl	%ebp, %eax
	jle	.L47
	movl	0(%r13,%rbp,4), %eax
	movl	(%rbx,%rbp,4), %r8d
	leal	2(%rbp), %ecx
	movq	%r14, %rsi
	movl	$2, %edi
	leal	1(%rax), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movslq	(%rbx,%rbp,4), %rax
	incq	%rbp
	addq	%rax, %r12
	jmp	.L42
.L47:
	leaq	.LC5(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIlEERSoT_@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	52(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L44
	call	__stack_chk_fail@PLT
.L44:
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3771:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3797:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3797:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include<stdio.h>
#include<math.h>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <cstring> 
using namespace std;



// R1 source, R2 destination,R3 weight
void initMSTEdgeList(int *R1 , int *R2 , int *R3, int *indexArray , int *destinationVertexArray, int *weightArray, int vertices)
{
	for(int v = indexArray[0] ; v < indexArray[1] ; v++)
	{
		// update weight of adjacent vertices of vertex 0. -1 bcz counting at r2 starts from 1 i.e at index 0 vertex 1 is placed.
		// So correspondingly for R3.
		R3[destinationVertexArray[v]-1] = weightArray[v];
	}	

	for(int i = 0;i< vertices-1;i++)
	{
		R2[i] = i+1;
		R1[i] = 0;
	}
}

void initializeGraph(int *indexArray , int *destinationVertexArray , int *weightArray, int edges)
{

	
	int u = 1,v,w;
	int count = 0;
	int prev = 1;
    for(int i = 0 ; i < edges ; i++) 
	{
	   prev = u;
       	   cin >>u>>v>>w;
	   if(prev == u)
	   {
			count++;
	   }	
	   else
	   {
		   indexArray[prev] = count + indexArray[prev-1];
		   count = 1;
	   }	
	   destinationVertexArray[i] = v-1;
	   weightArray[i] = w;
    }

}


void printArray(char name,int *a  , int size)
{
    printf("%c: ",name);
    for(int i = 0; i < size ; i++)
        printf("%d\t",a[i]);
    printf("\n");
}


void updateMSTList(int startIndex,int endIndex, int *nearestVertex, int *destinationVertexArray,int *weightArray,int *R1,int *R2,int *R3)
{
	
	for(int i = startIndex; i <= endIndex;i++)
	{	
		if(destinationVertexArray[i] != 0)
		{	
			if(R2[destinationVertexArray[i]-1] != 0)
			{	// -1 bcz the r2 & r3 counting begins from 1.// update the edge and the source vertex.
				if(R3[destinationVertexArray[i]-1] > weightArray[i] )
				{		
					R3[destinationVertexArray[i]-1] = weightArray[i];
					R1[destinationVertexArray[i]-1] = *nearestVertex;
				}
			}
		}
	}
}

void findNearestVertex(int *R1, int *R2 , int *R3, int *nearest_vertex,int vertices)
{

	int *min = (int *)malloc(sizeof(int));
	memset(min,1,sizeof(int));	

	for(int i = 0; i < vertices-1 ; i++)
	{
		if(R3[i] < (*min) && R2[i] != 0)
		{
			 *min = R3[i];
			*nearest_vertex = i+1;			
		}		
	}
	R2[(*nearest_vertex)-1] = 0;
}



int main()
{
	// graph representatioon arrays
	int *indexArray;
	int *weightArray;
	int *destinationVertexArray;


	// MST Edge list
	int *R1;
	int *R2;
	int *R3;
	int *nearestVertex;
   	

	
	int edges,vertices;
	cin>>vertices>>edges;
	edges = edges/2;	
	
	// iteration indexes for updation
	int startIndex, endIndex;
	
	// allocate memory to compact adjacency list

	indexArray = (int *)malloc(vertices * sizeof(int));
 	weightArray = (int *)malloc(2 * edges * sizeof(int));
    destinationVertexArray = (int *)malloc(2 * edges * sizeof(int));
	nearestVertex = (int *)malloc(sizeof(int));
	
	memset(indexArray,0,vertices * sizeof(int));
	memset(weightArray,0,2 * edges * sizeof(int));
	memset(destinationVertexArray,0,2 * edges * sizeof(int));
	*nearestVertex = 0;
	
	R1 = (int *)malloc((vertices-1) * sizeof(int));
	R2 = (int *)malloc((vertices-1) * sizeof(int));
	R3 = (int *)malloc((vertices-1) * sizeof(int));
	memset(R3,1,(vertices-1)*sizeof(int));
	
	initializeGraph(indexArray,destinationVertexArray,weightArray,2*edges);
	
	initMSTEdgeList(R1,R2,R3,indexArray,destinationVertexArray,weightArray,vertices);	


	
		hipEvent_t start, stop;
        float time;
        hipEventCreate(&start);
        hipEventCreate(&stop);
        hipEventRecord( start, 0 );
	
	// kernel launch
	for(int v = 0 ; v < vertices-2; v++)
	{
		findNearestVertex(R1, R2, R3, nearestVertex,vertices);

		startIndex = indexArray[*nearestVertex];
		if(*(nearestVertex) == vertices-1)
        		endIndex = 2*edges-1;
	    	else
        		endIndex = indexArray[*nearestVertex+1]-1;

		updateMSTList(startIndex, endIndex , nearestVertex, destinationVertexArray, weightArray, R1, R2, R3);
		
	}

        printf("u\tv\tw\n");
		long cost = 0;
		hipEventRecord( stop, 0 );
        hipEventSynchronize( stop );
        hipEventElapsedTime( &time, start, stop );
        hipEventDestroy( start );
        hipEventDestroy( stop );

        for(int i = 0; i < vertices-1;i++)
        {
       		 printf("%d\t%d\t%d\t\n",R1[i]+1,i+2,R3[i]);
		 cost = cost + R3[i];
        }
		cout<<"\ncost:"<<cost;
 		printf("\nTime: %fms\n",time);		
}
   

	.text
	.file	"SerialPrim.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z15initMSTEdgeListPiS_S_S_S_S_i # -- Begin function _Z15initMSTEdgeListPiS_S_S_S_S_i
	.type	_Z15initMSTEdgeListPiS_S_S_S_S_i,@function
_Z15initMSTEdgeListPiS_S_S_S_S_i:       # @_Z15initMSTEdgeListPiS_S_S_S_S_i
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	16(%rsp), %eax
	movslq	(%rcx), %r10
	cmpl	4(%rcx), %r10d
	jge	.LBB0_1
.LBB0_5:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%r9,%r10,4), %r11d
	movslq	(%r8,%r10,4), %rbx
	movl	%r11d, -4(%rdx,%rbx,4)
	incq	%r10
	movslq	4(%rcx), %r11
	cmpq	%r11, %r10
	jl	.LBB0_5
.LBB0_1:                                # %.preheader
	cmpl	$2, %eax
	jl	.LBB0_4
# %bb.2:                                # %.lr.ph19.preheader
	decl	%eax
	xorl	%ecx, %ecx
.LBB0_3:                                # %.lr.ph19
                                        # =>This Inner Loop Header: Depth=1
	leaq	1(%rcx), %rdx
	movl	%edx, (%rsi,%rcx,4)
	movl	$0, (%rdi,%rcx,4)
	movq	%rdx, %rcx
	cmpq	%rdx, %rax
	jne	.LBB0_3
.LBB0_4:                                # %._crit_edge
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z15initMSTEdgeListPiS_S_S_S_S_i, .Lfunc_end0-_Z15initMSTEdgeListPiS_S_S_S_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z15initializeGraphPiS_S_i      # -- Begin function _Z15initializeGraphPiS_S_i
	.type	_Z15initializeGraphPiS_S_i,@function
_Z15initializeGraphPiS_S_i:             # @_Z15initializeGraphPiS_S_i
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdx, 16(%rsp)                  # 8-byte Spill
	movl	$1, 4(%rsp)
	testl	%ecx, %ecx
	jle	.LBB1_6
# %bb.1:                                # %.lr.ph.preheader
	movq	%rsi, %r14
	movq	%rdi, %r15
	movl	%ecx, %r12d
	xorl	%r13d, %r13d
	movl	$1, %ebx
	xorl	%ebp, %ebp
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$_ZSt3cin, %edi
	leaq	4(%rsp), %rsi
	callq	_ZNSirsERi
	movq	%rax, %rdi
	leaq	12(%rsp), %rsi
	callq	_ZNSirsERi
	movq	%rax, %rdi
	leaq	8(%rsp), %rsi
	callq	_ZNSirsERi
	movl	4(%rsp), %eax
	cmpl	%eax, %ebx
	jne	.LBB1_4
# %bb.3:                                #   in Loop: Header=BB1_2 Depth=1
	incl	%ebp
	jmp	.LBB1_5
.LBB1_4:                                #   in Loop: Header=BB1_2 Depth=1
	movslq	%ebx, %rcx
	addl	-4(%r15,%rcx,4), %ebp
	movl	%ebp, (%r15,%rcx,4)
	movl	$1, %ebp
.LBB1_5:                                #   in Loop: Header=BB1_2 Depth=1
	movl	12(%rsp), %ecx
	decl	%ecx
	movl	%ecx, (%r14,%r13,4)
	movl	8(%rsp), %ecx
	movq	16(%rsp), %rdx                  # 8-byte Reload
	movl	%ecx, (%rdx,%r13,4)
	incq	%r13
	movl	%eax, %ebx
	cmpq	%r13, %r12
	jne	.LBB1_2
.LBB1_6:                                # %._crit_edge
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z15initializeGraphPiS_S_i, .Lfunc_end1-_Z15initializeGraphPiS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z10printArraycPii              # -- Begin function _Z10printArraycPii
	.type	_Z10printArraycPii,@function
_Z10printArraycPii:                     # @_Z10printArraycPii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebp
	movq	%rsi, %rbx
	movl	%edi, %esi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	testl	%ebp, %ebp
	jle	.LBB2_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %r14d
	xorl	%r15d, %r15d
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%r15,4), %esi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB2_2
.LBB2_3:                                # %._crit_edge
	movl	$10, %edi
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end2:
	.size	_Z10printArraycPii, .Lfunc_end2-_Z10printArraycPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z13updateMSTListiiPiS_S_S_S_S_ # -- Begin function _Z13updateMSTListiiPiS_S_S_S_S_
	.type	_Z13updateMSTListiiPiS_S_S_S_S_,@function
_Z13updateMSTListiiPiS_S_S_S_S_:        # @_Z13updateMSTListiiPiS_S_S_S_S_
	.cfi_startproc
# %bb.0:
                                        # kill: def $esi killed $esi def $rsi
	cmpl	%esi, %edi
	jg	.LBB3_8
# %bb.1:                                # %.lr.ph.preheader
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	24(%rsp), %rax
	movq	16(%rsp), %r10
	movslq	%edi, %r11
	leaq	(%rcx,%r11,4), %rcx
	leaq	(%r8,%r11,4), %r8
	subl	%edi, %esi
	incl	%esi
	xorl	%edi, %edi
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movslq	(%rcx,%rdi,4), %r11
	testq	%r11, %r11
	je	.LBB3_6
# %bb.3:                                #   in Loop: Header=BB3_2 Depth=1
	cmpl	$0, -4(%r10,%r11,4)
	je	.LBB3_6
# %bb.4:                                #   in Loop: Header=BB3_2 Depth=1
	movl	(%r8,%rdi,4), %ebx
	cmpl	%ebx, -4(%rax,%r11,4)
	jle	.LBB3_6
# %bb.5:                                #   in Loop: Header=BB3_2 Depth=1
	movl	%ebx, -4(%rax,%r11,4)
	movl	(%rdx), %r11d
	movslq	(%rcx,%rdi,4), %rbx
	movl	%r11d, -4(%r9,%rbx,4)
.LBB3_6:                                #   in Loop: Header=BB3_2 Depth=1
	incq	%rdi
	cmpl	%edi, %esi
	jne	.LBB3_2
# %bb.7:
	popq	%rbx
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
.LBB3_8:                                # %._crit_edge
	retq
.Lfunc_end3:
	.size	_Z13updateMSTListiiPiS_S_S_S_S_, .Lfunc_end3-_Z13updateMSTListiiPiS_S_S_S_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z17findNearestVertexPiS_S_S_i  # -- Begin function _Z17findNearestVertexPiS_S_S_i
	.type	_Z17findNearestVertexPiS_S_S_i,@function
_Z17findNearestVertexPiS_S_S_i:         # @_Z17findNearestVertexPiS_S_S_i
	.cfi_startproc
# %bb.0:
                                        # kill: def $r8d killed $r8d def $r8
	cmpl	$2, %r8d
	jl	.LBB4_6
# %bb.1:                                # %.lr.ph
	decl	%r8d
	movl	$16843009, %edi                 # imm = 0x1010101
	xorl	%eax, %eax
.LBB4_2:                                # =>This Inner Loop Header: Depth=1
	movl	(%rdx,%rax,4), %r9d
	cmpl	%edi, %r9d
	jge	.LBB4_5
# %bb.3:                                #   in Loop: Header=BB4_2 Depth=1
	cmpl	$0, (%rsi,%rax,4)
	je	.LBB4_5
# %bb.4:                                #   in Loop: Header=BB4_2 Depth=1
	leal	1(%rax), %edi
	movl	%edi, (%rcx)
	movl	%r9d, %edi
.LBB4_5:                                #   in Loop: Header=BB4_2 Depth=1
	incq	%rax
	cmpq	%rax, %r8
	jne	.LBB4_2
.LBB4_6:                                # %._crit_edge
	movslq	(%rcx), %rax
	movl	$0, -4(%rsi,%rax,4)
	retq
.Lfunc_end4:
	.size	_Z17findNearestVertexPiS_S_S_i, .Lfunc_end4-_Z17findNearestVertexPiS_S_S_i
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	12(%rsp), %rsi
	movl	$_ZSt3cin, %edi
	movq	%rsi, %r14
	callq	_ZNSirsERi
	leaq	36(%rsp), %rbx
	movq	%rax, %rdi
	movq	%rbx, %rsi
	callq	_ZNSirsERi
	movl	(%rbx), %eax
	movl	%eax, %ebp
	shrl	$31, %ebp
	addl	%eax, %ebp
	movl	%ebp, %eax
	sarl	%eax
	movl	%eax, (%rbx)
	movslq	(%r14), %r14
	leaq	(,%r14,4), %rsi
	movl	$1, %edi
	callq	calloc@PLT
	movq	%rax, %r15
	andl	$-2, %ebp
	movslq	%ebp, %rax
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	leaq	(,%rax,4), %rbx
	movl	$1, %edi
	movq	%rbx, %rsi
	callq	calloc@PLT
	movq	%rax, %r13
	movl	$1, %edi
	movq	%rbx, %rsi
	callq	calloc@PLT
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	leaq	-4(,%r14,4), %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %rbx
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %rbp
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	%rax, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	callq	memset@PLT
	movq	%r15, %rdi
	movq	40(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rsi
	movq	%r13, %rdx
	movq	24(%rsp), %rcx                  # 8-byte Reload
                                        # kill: def $ecx killed $ecx killed $rcx
	callq	_Z15initializeGraphPiS_S_i
	movq	%r12, %rdi
	leaq	12(%rsp), %rax
	movl	(%rax), %r12d
	movslq	(%r15), %rax
	movslq	4(%r15), %rcx
	cmpl	%ecx, %eax
	jge	.LBB5_1
.LBB5_25:                               # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	movl	(%r13,%rax,4), %edx
	movslq	(%rdi,%rax,4), %rsi
	movl	%edx, -4(%r14,%rsi,4)
	incq	%rax
	cmpq	%rax, %rcx
	jne	.LBB5_25
.LBB5_1:                                # %.preheader.i
	movq	%r13, 24(%rsp)                  # 8-byte Spill
	cmpl	$2, %r12d
	jl	.LBB5_4
# %bb.2:                                # %.lr.ph19.preheader.i
	decl	%r12d
	leaq	(,%r12,4), %rdx
	xorl	%r13d, %r13d
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB5_3:                                # %.lr.ph19.i
                                        # =>This Inner Loop Header: Depth=1
	leaq	1(%r13), %rax
	movl	%eax, (%rbp,%r13,4)
	movq	%rax, %r13
	cmpq	%rax, %r12
	jne	.LBB5_3
.LBB5_4:                                # %_Z15initMSTEdgeListPiS_S_S_S_S_i.exit
	leaq	48(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r12), %rdi
	xorl	%r12d, %r12d
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	12(%rsp), %eax
	cmpl	$3, %eax
	jl	.LBB5_21
# %bb.5:                                # %.lr.ph
	leal	-1(%rax), %ecx
	movl	36(%rsp), %edx
	addl	%edx, %edx
	addl	$-3, %eax
	xorl	%esi, %esi
.LBB5_6:                                # %.lr.ph.i48.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_7 Depth 2
                                        #     Child Loop BB5_15 Depth 2
	movl	$16843009, %r8d                 # imm = 0x1010101
	xorl	%edi, %edi
.LBB5_7:                                # %.lr.ph.i48
                                        #   Parent Loop BB5_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r14,%rdi,4), %r9d
	cmpl	%r8d, %r9d
	jge	.LBB5_10
# %bb.8:                                #   in Loop: Header=BB5_7 Depth=2
	cmpl	$0, (%rbp,%rdi,4)
	je	.LBB5_10
# %bb.9:                                #   in Loop: Header=BB5_7 Depth=2
	leal	1(%rdi), %r12d
	movl	%r9d, %r8d
.LBB5_10:                               #   in Loop: Header=BB5_7 Depth=2
	incq	%rdi
	cmpq	%rdi, %rcx
	jne	.LBB5_7
# %bb.11:                               # %_Z17findNearestVertexPiS_S_S_i.exit
                                        #   in Loop: Header=BB5_6 Depth=1
	movslq	%r12d, %r8
	movl	$0, -4(%rbp,%r8,4)
	movl	%edx, %edi
	cmpl	%ecx, %r8d
	je	.LBB5_13
# %bb.12:                               #   in Loop: Header=BB5_6 Depth=1
	movl	4(%r15,%r8,4), %edi
.LBB5_13:                               #   in Loop: Header=BB5_6 Depth=1
	movslq	(%r15,%r8,4), %r9
	cmpl	%r9d, %edi
	jle	.LBB5_20
# %bb.14:                               # %.lr.ph.preheader.i54
                                        #   in Loop: Header=BB5_6 Depth=1
	subl	%r9d, %edi
	movq	24(%rsp), %r8                   # 8-byte Reload
	leaq	(%r8,%r9,4), %r8
	movq	40(%rsp), %r10                  # 8-byte Reload
	leaq	(%r10,%r9,4), %r9
	xorl	%r10d, %r10d
.LBB5_15:                               # %.lr.ph.i55
                                        #   Parent Loop BB5_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movslq	(%r9,%r10,4), %r11
	testq	%r11, %r11
	je	.LBB5_19
# %bb.16:                               #   in Loop: Header=BB5_15 Depth=2
	cmpl	$0, -4(%rbp,%r11,4)
	je	.LBB5_19
# %bb.17:                               #   in Loop: Header=BB5_15 Depth=2
	movl	(%r8,%r10,4), %r13d
	cmpl	%r13d, -4(%r14,%r11,4)
	jle	.LBB5_19
# %bb.18:                               #   in Loop: Header=BB5_15 Depth=2
	movl	%r13d, -4(%r14,%r11,4)
	movl	%r12d, -4(%rbx,%r11,4)
.LBB5_19:                               #   in Loop: Header=BB5_15 Depth=2
	incq	%r10
	cmpl	%r10d, %edi
	jne	.LBB5_15
.LBB5_20:                               # %_Z13updateMSTListiiPiS_S_S_S_S_.exit
                                        #   in Loop: Header=BB5_6 Depth=1
	leal	1(%rsi), %edi
	cmpl	%eax, %esi
	movl	%edi, %esi
	jne	.LBB5_6
.LBB5_21:                               # %._crit_edge
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	16(%rsp), %rdi
	xorl	%r15d, %r15d
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	48(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	32(%rsp), %rdi
	callq	hipEventElapsedTime
	movq	48(%rsp), %rdi
	callq	hipEventDestroy
	movq	16(%rsp), %rdi
	callq	hipEventDestroy
	cmpl	$2, 12(%rsp)
	jl	.LBB5_24
# %bb.22:                               # %.lr.ph65.preheader
	xorl	%r13d, %r13d
	xorl	%r15d, %r15d
.LBB5_23:                               # %.lr.ph65
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%r13,4), %esi
	incl	%esi
	movslq	(%r14,%r13,4), %r12
	leal	2(%r13), %edx
	movl	$.L.str.4, %edi
	movl	%r12d, %ecx
	xorl	%eax, %eax
	callq	printf
	addq	%r12, %r15
	incq	%r13
	movslq	12(%rsp), %rax
	decq	%rax
	cmpq	%rax, %r13
	jl	.LBB5_23
.LBB5_24:                               # %._crit_edge66
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$6, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movq	%r15, %rsi
	callq	_ZNSo9_M_insertIlEERSoT_
	cvtss2sd	32(%rsp), %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%c: "
	.size	.L.str, 5

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"%d\t"
	.size	.L.str.1, 4

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%d\t%d\t%d\t\n"
	.size	.L.str.4, 11

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\ncost:"
	.size	.L.str.5, 7

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"\nTime: %fms\n"
	.size	.L.str.6, 13

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"u\tv\tw"
	.size	.Lstr, 6

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _ZSt3cin
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
