#include "libscl.h"

using namespace std;
using namespace scl;

int main() 
{

  string filename = "tstdijk.in";
  ifstream fin;
  fin.open(filename.c_str());
  if (!fin) error("Error, tstdijk, cannot open " + filename);

  cout << '\n';
  cout << "input nodes, edges" << '\n';
  INTEGER nodes, edges;
  fin >> nodes >> edges;
  cout << nodes << ' ' << edges << '\n';

  cout << '\n';
  cout << "input graph" << '\n';
  INTEGER u, v;
  REAL w;
  vector<edge> graph;
  for (INTEGER i=0; i<edges; i++) {
    fin >> u >> v >> w;
    cout << u << ' ' << v << ' ' << w << '\n';
    graph.push_back(edge(u,v,w));
  }
  
  cout << '\n';
  cout << "input start" << '\n';
  INTEGER start;
  fin >> start;
  cout << start << '\n';

  fin.clear(); fin.close();

  if (graph.size() != size_t(edges)) error("Error, should not happen");

  vector<intvec> path;
  realmat D = dijkstra(nodes, edges, start, graph, path);
  
  cout << '\n';
  cout << "returned D" << '\n';
  for(INTEGER i=1; i<=nodes; i++) {
    cout << "Node " << i << ", Distance = " << D[i] << '\n';
  }

  cout << '\n';
  cout << "returned path" << '\n';
  for (INTEGER i=1; i<=nodes; ++i) {
    INTEGER sz = path[i].size();
    cout << "Node " << i << ", Path = ";
    for (INTEGER j=1; j<=sz; ++j) {
      cout << path[i][j] << ' ';
    }
    cout << '\n';
  }
  cout << '\n';

  return 0; 
}
