»Ë»Ñ Æ÷·³
°³¹ßÀÚÆ÷·³ ÀÔ´Ï´Ù.
  • ºÏ¸¶Å© ¾ÆÀÌÄÜ

C¾ð¾î·Î Prim ¾Ë°í¸®Áò ±¸ÇöÇÏ¿´´Âµ¥ Áú¹®Á» µå·Áµµ µÉ±î¿ä..?8

#include "stdafx.h"
#include

const double INF=1e10;

struct Edge {
        int v1, v2;
};

void Prim(const int n,  double W[10][10], Edge F[]);


void main()
{
        const int n=10;
        double W[10][10]={
                {0, 32, INF, 17, INF, INF, INF, INF, INF, INF},
                {32, 0, INF, INF, 45, INF, INF, INF, INF, INF},
                {INF, INF, 0, 18, INF, INF, 5, INF, INF, INF},
                {17, INF, 18, 0, 10, INF, INF, 3, INF, INF},
                {INF, 45, INF, 10, 0, 28, INF, INF, 25, INF},
                {INF, INF, INF, INF, 28, 0, INF, INF, INF, 6},
                {INF, INF, 5, INF, INF, INF, 0, 59, INF, INF},
                {INF, INF, INF, 3, INF, INF, 59, 0, 4, INF},
                {INF, INF, INF, INF, 25, INF, INF, 4, 0, 12},
                {INF, INF, INF, INF, INF, 6, INF, INF, 12, 0}
        };
        Edge mst[100];
        int i;

        Prim(10, W, mst);

        for (i=2;i<=mst[0].v1+1;i++)<br />                 printf("%d<-->%dn", mst[i].v1, mst[i].v2);

}


void Prim(const int n, double W[10][10], Edge F[])
{

        int i, k, vnear;
        double min;                
        Edge e;                        //edge
        int *nearest=new int[n];
        double *distance=new double[n];

        F[0].v1=0;

        for (i=2;i         {
                nearest[i]=1;  //Ãʱ⿡´Â Y¿¡ ³ëµå°¡ v1Çϳª
                distance[i]=W[1][i]; //v1,viÀÇ °¡ÁßÄ¡·Î ÃʱâÈ­
        }

        for (k=2;k         {

                min=INF;
                for (i=2;i                 {
                        if (0<=distance[i] && distance[i]<min)<br />                         {
                                min=distance[i];
                                vnear=i;
                        }
                }
                e.v1=vnear;
                e.v2=nearest[vnear];
                F[k]=e;
                F[0].v1++;
                distance[vnear]=-1;
                for (i=2;i                 {
                        if (W[i][vnear]                         {
                                distance[i]=W[i][vnear];
                                nearest[i]=vnear;
                        }
                }
        }

        //delete [] nearest;
        //delete [] distance;
}




ÀÌ·¸°Ô ±¸ÇöÇÏ¿´´Âµ¥ Ãâ·ÂÇÏ¿´À»¶§ Á¦°¡ ¼ÕÀ¸·Î Ç®¾ú´ø °Í°ú´Â ´Ù¸£°Ô Ãâ·ÂµÇ³×¿ä ¤Ð¤Ð
¾îµð°¡ Ʋ·È´ÂÁö Á¶¾ðÁ» ºÎŹµå¸®°Ú½À´Ï´Ù!

0
ÃßõÇϱ⠴ٸ¥ÀÇ°ß 0
|
°øÀ¯¹öÆ°

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¿À´Ãµµ´Þ¸®°í³»Àϵµ´Þ¸®°í¸ð·¹µµ´Þ¸®¸é¼ûÂü

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¹é¾Æ

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 °¨°¢

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¿À´Ãµµ´Þ¸®°í³»Àϵµ´Þ¸®°í¸ð·¹µµ´Þ¸®¸é¼ûÂü

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¾Õ±æÀ̱¸¸¸¸®

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ÀÕÄ«Äí

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ²õ²õ²õ

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¿À´Ãµµ´Þ¸®°í³»Àϵµ´Þ¸®°í¸ð·¹µµ´Þ¸®¸é¼ûÂü
  • ¾Ë¸² ¿å¼³, »óó ÁÙ ¼ö ÀÖ´Â ¾ÇÇÃÀº »ï°¡ÁÖ¼¼¿ä.
©¹æ »çÁø  
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û ¸ñ·Ïº¸±â