Cod sursa(job #1574768)

Utilizator bogdanciurezubogdan ciurezu bogdanciurezu Data 20 ianuarie 2016 20:23:36
Problema Parcurgere DFS - componente conexe Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

const int nmax = 100000;

vector < pair<int, int> > graf[nmax];

unsigned int n, m;
int nrCuv;
unsigned int cost[nmax];

inline int minim(int x, int y){
    return (x < y) ? x : y;
}

void dfs(int nod){

    for(int i = 0; i < graf[nod].size(); ++i){
        pair<int, int> node = graf[nod][i];

        if( minim(cost[nod], node.second) > cost[node.first] ){
            cost[ node.first ] = minim(cost[nod], node.second);
            dfs(node.first);
        }
    }
}

int main()
{
    f>>n>>m;

    for(int i = 1, x, y, w; i <= m; ++i){
        f>>x>>y>>w;
        graf[x].push_back( make_pair(y, w) );
        graf[y].push_back( make_pair(x, w) );
    }


    cost[1] = 10050;
    dfs(1);

    g<<cost[n]<<'\n';

    return 0;
}