-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHIGHWAYS.cpp
More file actions
106 lines (100 loc) · 1.94 KB
/
Copy pathHIGHWAYS.cpp
File metadata and controls
106 lines (100 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*Sushil Kumar Singh */
#include <cassert>
#include <cctype>
#include <cfloat>
#include <cmath>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
#include <ext/numeric>
#include <ext/hash_map>
#include <ext/hash_set>
#include <ext/algorithm>
using namespace std;
using namespace __gnu_cxx;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t, n,m,s,e,x,y,v;
ii p;
cin>>t;
while(t--)
{
cin>>n>>m>>s>>e;
vvii paths(n+1);
for(int i=0;i<m;i++)
{
cin>>x>>y>>v;
p.first=y; p.second=v;
paths[x].push_back(p);
}
for(int i=1;i<paths.size();i++)
{
cout<<i<<" -- ";
for(int j=0;j<paths[i].size();j++)
{
cout<<"("<<paths[i][j].first<<" "<<paths[i][j].second<<")";
}
cout<<endl;
}
vi D(n+1, 987654321);
priority_queue< ii, vector<ii>, greater<ii> > Q;
D[s]=0;
Q.push(ii(s,0));
while(!Q.empty())
{
ii top = Q.top();
Q.pop();
int v=top.first, d=top.second;
cout<<v<<" "<<d<<endl;
if(d<=D[v])
{
for(int i=0;i<paths[v].size();i++)
{
ii temp = paths[v][i];
int v2 = temp.first, cost=top.second;
cout<<"inserting "<<v2<<" "<<cost<<endl;
if(D[v2]>D[v]+cost)
{
D[v2]=D[v]+cost;
Q.push(ii(v2, D[v2]));
}
}
}
}
if(D[e]!=987654321)
cout<<"NONE"<<endl;
else
cout<<D[e]<<endl;
}
system("pause");
}