Cod sursa(job #2505909)

Utilizator Vaida_Radu_AndreiVaida Radu Andrei Vaida_Radu_Andrei Data 7 decembrie 2019 11:44:36
Problema Algoritmul lui Dijkstra Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.73 kb
#include <cstdio>
#include <vector>
#include <set>
#define verticesMax 51024
#define infinite 2<<30

using namespace std;

class Arc {
public:
    int to,cost;

    Arc();
    Arc(int newTo,int newFrom);
};

Arc::Arc() {
}

Arc::Arc(int newTo,int newCost) {
    to=newTo;
    cost=newCost;
}

class Vert {
public:
    int pos,cost;

    Vert();
    Vert(int newPos,int newCost);

    bool operator < (const Vert&Other) const;
};

bool Vert::operator < (const Vert&Other) const {
    return 0x1;
}

int vertices;
int costs[verticesMax],viz[verticesMax];
vector <Arc> Graph[verticesMax];
set <Vert> DGraph;

int takeMin(int x,int y) {
    return (x<y)*(x-y)+y;
}

void readArc() {
    int newFrom,newTo,newCost;
    scanf("%d%d%d",&newFrom,&newTo,&newCost);
    Arc R(newTo,newCost);
    Graph[newFrom].push_back(R);
}

void setCosts() {
    int i;
    for(i=0;i<vertices;++i) {
        costs[i]=infinite;
    }
}

void read() {
    int i,arces;
    scanf("%d%d",&vertices,&arces);
    for(i=0;i<arces;++i) {
        readArc();
    }
    setCosts();
}

void advance(Vert&MinV) {
    for(auto&Tie:Graph[MinV.pos]) {
        if() {
        }
    }
}

void solve() {
    int i;
    Vert F(0,0);
    DGraph.insert(F);
    for(i=1;i<vertices;++i) {
        advance(DGraph.begin());
        DGraph.erase(DGraph.begin());
    }
}

void display() {
    int i;
    for(i=1;i<vertices;++i) {
        if(costs[i]==infinite) {
            printf("0 ");
        }
        else {
            printf("%d ",costs[i]);
        }
    }
}

int main()
{
    freopen("dijkstra.in","r",stdin);
    freopen("dijkstra.out","w",stdout);
    read();
    solve();
    display();
    return 0;
}