Cod sursa(job #2358087)

Utilizator Cristian25Cristian Stanciu Cristian25 Data 27 februarie 2019 21:20:43
Problema Ubuntzei Scor 10
Compilator cpp-64 Status done
Runda simulare_oji_cls12_nr6 Marime 0.96 kb
#include <fstream>
#include <vector>
#include <queue>
#define dim 10010
#define pb push_back

using namespace std;

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

typedef pair<int, int> p;

vector<p> v[dim];
queue<int> q;

long long cost[dim];
int N, M, K;

void bfs(int nod)
{
    q.push(nod);
    while(!q.empty())
    {
        int el = q.front();
        q.pop();
        for(int i = 0; i < v[el].size(); ++i)
            if(cost[v[el][i].first] > cost[el] + v[el][i].second)
            {
                cost[v[el][i].first] = cost[el] + v[el][i].second;
                q.push(v[el][i].first);
            }
    }
}

int main()
{
    in >> N >> M >> K;
    for(int i = 1; i <= M; ++i)
    {
        int x, y, z;
        in >> x >> y >> z;
        v[x].pb({y, z});
    }
    cost[1] = 0;
    #define inf 0x3f3f3f3f
    for(int i = 2; i <= N; ++i)
        cost[i] = inf;
    bfs(1);
    out << cost[N];
    return 0;
}