Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class Node{
- public:
- int destination;
- int weight;
- Node *next;
- };
- class Integer{
- public:
- Node *head = NULL;
- };
- void addEdge(Integer arr[],int sorc,int dest,int w)
- {
- Node *newNode = new Node();
- newNode->destination = dest;
- newNode->weight = w;
- newNode->next = NULL;
- if( arr[sorc].head == NULL)
- arr[sorc].head = newNode;
- else
- {
- Node *temp = arr[sorc].head;
- while(temp->next != NULL)
- temp = temp->next;
- temp->next = newNode;
- }
- }
- void display(Integer listt[], int v)
- {
- for(int i =0; i<=v; i++)
- {
- cout<<"\n Adjacency list of vertex "<<i<<" -->";
- while(listt[i].head != NULL)
- {
- cout<<" "<<listt[i].head->destination<<" "<<listt[i].head->weight;
- listt[i].head = listt[i].head->next;
- }
- }
- }
- int shortestDist(int n)
- {
- int cost[100000];
- int dest[10000];
- cost[n] = 0;
- for (int j = n-1 ; j >=1 ; j--)
- {
- dist[i] = min(dist[i], graph[i][j] +
- dist[j]);
- }
- }
- int main()
- {
- freopen("input.txt","r",stdin);
- int v;
- cin>>v;
- Integer arr[v];
- /// eita na korle arr er vitore v+1 dite hobe
- for (int i = 0; i <= v; i++)
- arr[i].head = NULL;
- /// getting input
- int m,n,w;
- while(scanf("%d%d%d",&m,&n,&w) == 3)
- {
- addEdge(arr,m,n,w);
- //addEdge(arr,n,m);
- }
- display(arr,v);
- int result = shortestDist(arr,v);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement