ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1450. Russian Pipelines

Wrong Answer #5 Some test please
Posted by Manflack 7 Jul 2017 00:10
#include <iostream>
#include <vector>
#include <queue>
#define INF (1<<29)
using namespace std;

struct Arista
{
    int hasta,costo;
};

Arista armar(int h,int c)
{
    Arista ar;
    ar.hasta=h;
    ar.costo=c;
    return ar;
}

struct Grafo
{
    int suma=0;

    vector <vector <Arista>> adj;
    vector <int> dist;
    vector <bool> visitado;
    bool encontro=false;

    int nodos,aristas;
    int S,F;

    void leer()
    {
        cin >> nodos >> aristas;
        adj.resize(nodos+1);
        dist.resize(nodos+1,INF);
        visitado.resize(nodos+1,false);

        int desde,hasta,costo;
        for(int c=0; c<aristas; c++)
        {
            cin >> desde >> hasta >> costo;
            adj[desde].push_back(armar(hasta,costo));
        }

        cin >> S >> F;
        dist[S]=0;
    }

    void bdfs(int nodo, int padre)
    {

        visitado[nodo]=true;

        for(int c=0; c<adj[nodo].size(); c++)
        {
            int vecino=adj[nodo][c].hasta;
            int costo=adj[nodo][c].costo;
            if(dist[vecino]>dist[nodo]+costo&&visitado[vecino]==false)
            {
                dist[vecino]=dist[nodo]+costo;
                bdfs(vecino,nodo);
            }
        }
    }


    void start()
    {
        if(dist[F]<INF) cout << dist[F];
        else cout << "No solution";
    }

};

int main()
{
    Grafo g;
    g.leer();
    g.bdfs(g.S,-1);
    g.start();
    cout << endl;
    return 0;
}


BFS+DFS
Some test, guys?