Cod sursa(job #2358124)

Utilizator Cristian25Cristian Stanciu Cristian25 Data 27 februarie 2019 21:33:26
Problema Ubuntzei Scor 20
Compilator cpp-64 Status done
Runda simulare_oji_cls12_nr6 Marime 0.92 kb
#include <fstream>
#include <cassert>
#include <vector>
#define dim 150000
#define pb push_back

using namespace std;

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

typedef pair<long long, long long> p;

vector<p> v[dim];

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

void dfs(long long nod)
{
    for(long long i = 0; i < v[nod].size(); ++i)
        if(cost[v[nod][i].first] == -1 || cost[v[nod][i].first] > cost[nod] + v[nod][i].second)
        {
            cost[v[nod][i].first] = cost[nod] + v[nod][i].second;
            dfs(v[nod][i].first);
        }
}

int main()
{
    in >> N >> M >> K;
    assert(K == 0);
    for(long long i = 1; i <= M; ++i)
    {
        long long x, y, z;
        in >> x >> y >> z;
        v[x].pb({y, z});
        v[y].pb({x, z});
    }
    cost[1] = 0;
    for(long long i = 2; i <= N; ++i)
        cost[i] = -1;
    dfs(1);
    out << cost[N];
    return 0;
}