Cod sursa(job #709470)

Utilizator horeste12Stoianovici Horatiu Andrei horeste12 Data 8 martie 2012 09:50:15
Problema Arbore partial de cost minim Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.58 kb
#include <fstream>
#define fs(x) x*2
#define fd(x) x*2+1
using namespace std;

ifstream f("apm.in");
ofstream g("apm.out");

typedef struct nod
{
    int inf,c;
    nod *urm;
} NOD;
typedef NOD *graf[100010];
graf G;
struct muchie
{
    int x,y,c;
} heap[400010];

int n,m,v[100010],poz[100010];

void citire()
{
    f>>n>>m;
    int a,b,c;
    NOD *p,*q;
    for(int i=0;i<m;i++)
    {
        f>>a>>b>>c;
        p=new NOD;p->inf=b;p->c=c; p->urm=G[a];G[a]=p;
        q=new NOD;q->inf=a;q->c=c; q->urm=G[b];G[b]=q;
    }
    f.close();
}

void sift(int i)
{
    int ok=1;
    while(ok)
        if(heap[i].c>heap[fd(i)].c)
        {
            if(heap[i].c>heap[fs(i)].c)
            {
                int aux;
                if(heap[fs(i)].c<heap[fd(i)].c)
                    aux=fs(i);
                else
                    aux=fd(i);
                swap(heap[i],heap[aux]);
                i=aux;
            }
            else
            {
                swap(heap[i],heap[fs(i)]);
                i=fs(i);
            }
        }
        else
        if(heap[i].c>heap[fd(i)].c)
        {
            swap(heap[i],heap[fd(i)]);
            i=fd(i);
        }
        else
            ok=0;
}

void percolate(int i)
{
    int ok=1;
    while(ok)
        if(heap[i].c<heap[i/2].c)
        {
            swap(heap[i],heap[i/2]);
            i/=2;
        }
        else
            ok=0;
}

void add(int x,int y,int c)
{
    muchie aux;
    aux.x=x;aux.y=y;aux.c=c;
}
int main()
{
    citire();

    return 0;
}