Cod sursa(job #2417868)

Utilizator ALEx6430Alecs Andru ALEx6430 Data 1 mai 2019 23:24:47
Problema Algoritmul lui Dijkstra Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.14 kb
#include <fstream>
#include <vector>
#include <queue>
#define INF 1000000000
using namespace std;

ifstream in("dijkstra.in");
ofstream out("dijkstra.out");

vector<int> d;

struct mycomp
{
    bool operator() (int &a, int &b)
    {
        return d[a] > d[b];
    }
};

int main()
{
    int n, m;
    in >> n >> m;

    d.assign(n+1,INF);
    d[1] = 0;

    vector<pair<int,int>> v[n+1];

    for(int i = 0; i < m; i++)
    {
        int x, y, c;
        in >> x >> y >> c;

        v[x].push_back({y,c});
    }

    vector<bool> vis(n+1,false);
    priority_queue<int,vector<int>,mycomp> pq;
//    pq.push(1);
//
//    while(!pq.empty())
//    {
//        int nod = pq.top();
//        pq.pop();
//
//        for(auto it: v[nod])
//        {
//            int act = it.first;
//            int cost = it.second;
//
//            if(!vis[act])
//            {
//                d[act] = min(d[act],d[nod]+cost);
//                pq.push(act);
//            }
//        }
//
//        vis[nod] = true;
//    }
//
//    for(int i = 2; i <= n; i++) out << (d[i] == INF ? 0 : d[i]) << ' ';

    return 0;
}