Language: C++

// C++ program to print all paths from a source to destination. 
#include<bits/stdc++.h> 
#include <list> 
using namespace std; 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
#define int ll;// C++ program to print all paths from a source to destination. 
#include<bits/stdc++.h> 
#include <list> 
using namespace std; 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

// A directed graph using adjacency list representation 
class Graph 
{ 
  int V; // No. of vertices in graph 
  list<int> *adj; // Pointer to an array containing adjacency lists 

  // A recursive function used by printAllPaths() 
  void printAllPathsUtil(int , int , bool [], int [], int &); 

public: 
  Graph(int V); // Constructor 
  void addEdge(int u, int v); 
  void printAllPaths(int s, int d); 
}; 

Graph::Graph(int V) 
{ 
  this->V = V; 
  adj = new list<int>[V]; 
} 

void Graph::addEdge(int u, int v) 
{ 
  adj[u].push_back(v); // Add v to u’s list. 
} 

// Prints all paths from 's' to 'd' 
void Graph::printAllPaths(int s, int d) 
{ 
  // Mark all the vertices as not visited 
  bool *visited = new bool[V]; 

  // Create an array to store paths 
  int *path = new int[V]; 
  int path_index = 0; // Initialize path[] as empty 

  // Initialize all vertices as not visited 
  for (int i = 0; i < V; i++) 
    visited[i] = false; 

  // Call the recursive helper function to print all paths 
  printAllPathsUtil(s, d, visited, path, path_index); 
} 

// A recursive function to print all paths from 'u' to 'd'. 
// visited[] keeps track of vertices in current path. 
// path[] stores actual vertices and path_index is current 
// index in path[] 
vector<int> v[25001];
int cou=0;

void Graph::printAllPathsUtil(int u, int d, bool visited[], 
              int path[], int &path_index) 
{ 
  // Mark the current node and store it in path[] 
  visited[u] = true; 
  path[path_index] = u; 
  path_index++; 

  // If current vertex is same as destination, then print 
  // current path[] 
  if (u == d) 
  { 
    for (int i = 0; i<path_index; i++) 
      v[cou].push_back(path[i]); 
    cou++;
    
  } 
  else // If current vertex is not destination 
  { 
    // Recur for all the vertices adjacent to current vertex 
    list<int>::iterator i; 
    for (i = adj[u].begin(); i != adj[u].end(); ++i) 
      if (!visited[*i]) 
        printAllPathsUtil(*i, d, visited, path, path_index); 
  } 

  // Remove current vertex from path[] and mark it as unvisited 
  path_index--; 
  visited[u] = false; 
} 

// Driver program 
int main() 
{ 
  // Create a graph given in the above diagram 
   IOS
 
  int n,m,p;
  cin>>n>>m>>p;
  Graph g(n);
  Graph g1(n);
  bool cu[n+1];
  memset(cu,0,sizeof(cu));
  int x[n+1][n+1];
  memset(x,0,sizeof(x));
  for(int i=1;i<=m;++i)
  {
    int a,b,c;
    cin>>a>>b>>c;
    a--,b--;
    if(a==b and c!=1)
      cu[a]=1;
    else
    {
      g.addEdge(a,b);
      g1.addEdge(b,a);
      x[a][b]=c;

    }
  } 
  
  g.printAllPaths(0, n-1);
  vector<int> cost;
  vector<int> cost1;

  for(int i=0;i<=25000;++i)
  {
    if(v[i].size()==0)
      continue;
    else
    {
      int temp=0;
      for(int j=1;j<v[i].size();++j)
      {
        if(cu[v[i][j]])
        {
          cout<<-1;
          return 0;
        }
        temp+=x[v[i][j-1]][v[i][j]];
      }
     // cout<<temp<<endl;
      temp-=p*(v[i].size()-1);

      
        cost.push_back(temp);
      //cout<<endl;
    }
  } 
  for(int i=0;i<=25000;++i)
    v[i].clear();
  g.printAllPaths(n-1,0);
  for(int i=0;i<=25000;++i)
  {
    if(v[i].size()==0)
      continue;
    else
    {
      int temp=0;
      for(int j=1;j<v[i].size();++j)
      {
        if(cu[v[i][j]])
        {
          cout<<-1;
          return 0;
        }
        temp+=x[v[i][j]][v[i][j-1]];
      }
      cout<<temp<<endl;
      temp-=p*(v[i].size()-1);

      
        cost1.push_back(temp);
      //cout<<endl;
    }
  }
  sort(cost.begin(),cost.end(),greater<ll>());
  sort(cost1.begin(),cost1.end(),greater<ll>());
  if(cost1.size()==0)
  {
    cout<<max(cost[0],(ll)0);
  }
  else
  {
    if(cost1[0]+cost[0]>0)
    {
      cout<<-1<<endl;
      return 0;
    }
    if(cost1[0]<=0)
    {
           cout<<max(cost[0],(ll)0);
           return 0;   
    }
    if(cost[0]<0 and cost1[0]+cost[0]==0)
    {
      cout<<0;
      return 0;
    }
    if(cost[0]+cost1[0]<0)
    {
      cout<<0<<endl;
      return 0;
    }
  }





  return 0; 
} 



Compiler output:
a.cc:7:13: error: declaration does not declare anything [-fpermissive]
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |             ^~
a.cc:16:3: note: in expansion of macro 'int'
   16 |   int V; // No. of vertices in graph
      |   ^~~
a.cc:16:7: error: 'V' does not name a type
   16 |   int V; // No. of vertices in graph
      |       ^
a.cc:7:13: error: template argument 1 is invalid
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |             ^~
a.cc:17:8: note: in expansion of macro 'int'
   17 |   list<int> *adj; // Pointer to an array containing adjacency lists
      |        ^~~
a.cc:7:13: error: template argument 2 is invalid
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |             ^~
a.cc:17:8: note: in expansion of macro 'int'
   17 |   list<int> *adj; // Pointer to an array containing adjacency lists
      |        ^~~
a.cc:17:11: error: expected unqualified-id before '>' token
   17 |   list<int> *adj; // Pointer to an array containing adjacency lists
      |           ^
a.cc:7:15: error: expected ')' before ';' token
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |               ^
a.cc:20:26: note: in expansion of macro 'int'
   20 |   void printAllPathsUtil(int , int , bool [], int [], int &);
      |                          ^~~
a.cc:20:25: note: to match this '('
   20 |   void printAllPathsUtil(int , int , bool [], int [], int &);
      |                         ^
a.cc:20:30: error: expected unqualified-id before ',' token
   20 |   void printAllPathsUtil(int , int , bool [], int [], int &);
      |                              ^
a.cc:20:36: error: expected unqualified-id before ',' token
   20 |   void printAllPathsUtil(int , int , bool [], int [], int &);
      |                                    ^
a.cc:20:51: error: expected unqualified-id before '[' token
   20 |   void printAllPathsUtil(int , int , bool [], int [], int &);
      |                                                   ^
a.cc:20:60: error: expected unqualified-id before ')' token
   20 |   void printAllPathsUtil(int , int , bool [], int [], int &);
      |                                                            ^
a.cc:7:15: error: expected ')' before ';' token
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |               ^
a.cc:23:9: note: in expansion of macro 'int'
   23 |   Graph(int V); // Constructor
      |         ^~~
a.cc:23:8: note: to match this '('
   23 |   Graph(int V); // Constructor
      |        ^
a.cc:23:13: error: 'V' does not name a type
   23 |   Graph(int V); // Constructor
      |             ^
a.cc:7:15: error: expected ')' before ';' token
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |               ^
a.cc:24:16: note: in expansion of macro 'int'
   24 |   void addEdge(int u, int v);
      |                ^~~
a.cc:24:15: note: to match this '('
   24 |   void addEdge(int u, int v);
      |               ^
a.cc:24:20: error: 'u' does not name a type
   24 |   void addEdge(int u, int v);
      |                    ^
a.cc:24:27: error: 'v' does not name a type
   24 |   void addEdge(int u, int v);
      |                           ^
a.cc:7:15: error: expected ')' before ';' token
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |               ^
a.cc:25:22: note: in expansion of macro 'int'
   25 |   void printAllPaths(int s, int d);
      |                      ^~~
a.cc:25:21: note: to match this '('
   25 |   void printAllPaths(int s, int d);
      |                     ^
a.cc:25:26: error: 's' does not name a type
   25 |   void printAllPaths(int s, int d);
      |                          ^
a.cc:25:33: error: 'd' does not name a type
   25 |   void printAllPaths(int s, int d);
      |                                 ^
a.cc:7:15: error: expected ')' before ';' token
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |               ^
a.cc:28:14: note: in expansion of macro 'int'
   28 | Graph::Graph(int V)
      |              ^~~
a.cc:28:13: note: to match this '('
   28 | Graph::Graph(int V)
      |             ^
a.cc:28:1: error: declaration of 'Graph::Graph(ll)' outside of class is not definition [-fpermissive]
   28 | Graph::Graph(int V)
      | ^~~~~
a.cc:28:18: error: 'V' does not name a type
   28 | Graph::Graph(int V)
      |                  ^
a.cc:7:15: error: expected ')' before ';' token
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |               ^
a.cc:34:21: note: in expansion of macro 'int'
   34 | void Graph::addEdge(int u, int v)
      |                     ^~~
a.cc:34:20: note: to match this '('
   34 | void Graph::addEdge(int u, int v)
      |                    ^
a.cc:34:6: error: declaration of 'void Graph::addEdge(ll)' outside of class is not definition [-fpermissive]
   34 | void Graph::addEdge(int u, int v)
      |      ^~~~~
a.cc:34:25: error: 'u' does not name a type
   34 | void Graph::addEdge(int u, int v)
      |                         ^
a.cc:34:32: error: 'v' does not name a type
   34 | void Graph::addEdge(int u, int v)
      |                                ^
a.cc:7:15: error: expected ')' before ';' token
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |               ^
a.cc:40:27: note: in expansion of macro 'int'
   40 | void Graph::printAllPaths(int s, int d)
      |                           ^~~
a.cc:40:26: note: to match this '('
   40 | void Graph::printAllPaths(int s, int d)
      |                          ^
a.cc:40:6: error: declaration of 'void Graph::printAllPaths(ll)' outside of class is not definition [-fpermissive]
   40 | void Graph::printAllPaths(int s, int d)
      |      ^~~~~
a.cc:40:31: error: 's' does not name a type
   40 | void Graph::printAllPaths(int s, int d)
      |                               ^
a.cc:40:38: error: 'd' does not name a type
   40 | void Graph::printAllPaths(int s, int d)
      |                                      ^
a.cc:7:13: error: template argument 1 is invalid
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |             ^~
a.cc:61:8: note: in expansion of macro 'int'
   61 | vector<int> v[25001];
      |        ^~~
a.cc:7:13: error: template argument 2 is invalid
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |             ^~
a.cc:61:8: note: in expansion of macro 'int'
   61 | vector<int> v[25001];
      |        ^~~
a.cc:61:11: error: expected unqualified-id before '>' token
   61 | vector<int> v[25001];
      |           ^
a.cc:7:13: error: declaration does not declare anything [-fpermissive]
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |             ^~
a.cc:62:1: note: in expansion of macro 'int'
   62 | int cou=0;
      | ^~~
a.cc:62:5: error: 'cou' does not name a type
   62 | int cou=0;
      |     ^~~
a.cc:7:15: error: expected ')' before ';' token
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |               ^
a.cc:64:31: note: in expansion of macro 'int'
   64 | void Graph::printAllPathsUtil(int u, int d, bool visited[],
      |                               ^~~
a.cc:64:30: note: to match this '('
   64 | void Graph::printAllPathsUtil(int u, int d, bool visited[],
      |                              ^
a.cc:64:6: error: declaration of 'void Graph::printAllPathsUtil(ll)' outside of class is not definition [-fpermissive]
   64 | void Graph::printAllPathsUtil(int u, int d, bool visited[],
      |      ^~~~~
a.cc:64:35: error: 'u' does not name a type
   64 | void Graph::printAllPathsUtil(int u, int d, bool visited[],
      |                                   ^
a.cc:64:42: error: 'd' does not name a type
   64 | void Graph::printAllPathsUtil(int u, int d, bool visited[],
      |                                          ^
a.cc:65:19: error: 'path' does not name a type
   65 |               int path[], int &path_index)
      |                   ^~~~
a.cc:65:42: error: expected constructor, destructor, or type conversion before ')' token
   65 |               int path[], int &path_index)
      |                                          ^
a.cc:7:13: error: declaration does not declare anything [-fpermissive]
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |             ^~
a.cc:96:1: note: in expansion of macro 'int'
   96 | int main()
      | ^~~
a.cc:96:5: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   96 | int main()
      |     ^~~~
a.cc: In function 'int main()':
a.cc:7:13: error: declaration does not declare anything [-fpermissive]
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |             ^~
a.cc:101:3: note: in expansion of macro 'int'
  101 |   int n,m,p;
      |   ^~~
a.cc:101:7: error: 'n' was not declared in this scope; did you mean 'yn'?
  101 |   int n,m,p;
      |       ^
      |       yn
a.cc:101:9: error: 'm' was not declared in this scope; did you mean 'tm'?
  101 |   int n,m,p;
      |         ^
      |         tm
a.cc:101:11: error: 'p' was not declared in this scope
  101 |   int n,m,p;
      |           ^
a.cc:106:10: error: 'cu' was not declared in this scope
  106 |   memset(cu,0,sizeof(cu));
      |          ^~
a.cc:7:13: error: declaration does not declare anything [-fpermissive]
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |             ^~
a.cc:107:3: note: in expansion of macro 'int'
  107 |   int x[n+1][n+1];
      |   ^~~
a.cc:107:7: error: 'x' was not declared in this scope
  107 |   int x[n+1][n+1];
      |       ^
a.cc:7:13: error: declaration does not declare anything [-fpermissive]
    7 | #define int ll;// C++ program to print all paths from a source to destination.
      |             ^~
a.cc:109:7: note