-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAPRIL17CLIQUED.cpp
More file actions
60 lines (58 loc) · 1.63 KB
/
APRIL17CLIQUED.cpp
File metadata and controls
60 lines (58 loc) · 1.63 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
#include<set>
#include<vector>
#include<iostream>
#include<climits>
const long long INF=INT_MAX;
using namespace std;
struct edge { long long to, length; };
void dijkstra(vector< vector<edge> > &graph, long long source)
{ vector<long long> min_distance( graph.size(), INF );
min_distance[ source ] = 0;
set< pair<long long, long long> > active_vertices;
active_vertices.insert( {0,source} );
while (!active_vertices.empty())
{ long long where = active_vertices.begin()->second;
active_vertices.erase( active_vertices.begin() );
for (auto ed : graph[where])
if (min_distance[ed.to] > min_distance[where] + ed.length)
{ active_vertices.erase( { min_distance[ed.to], ed.to } );
min_distance[ed.to] = min_distance[where] + ed.length;
active_vertices.insert( { min_distance[ed.to], ed.to } );
}
}
for(long long i=0; i<graph.size(); i++)
{ cout<<min_distance[i]<<' ';
}
cout<<'\n';
}
void solve()
{ long long N, K, X, M, S;
cin>>N>>K>>X>>M>>S;
vector< vector<edge> > gr(N);//first element in the pair is the node number and 2nd one is distance.
for(long long i=0; i<K; i++)
{ for(long long j=0; j<K; j++)
{ struct edge one={j, X}, two={i, X};
gr[i].push_back(one);
gr[j].push_back(two);
}
}
while(M--)
{ long long a, b, c;
cin>>a>>b>>c;
struct edge one={b-1, c}, two={a-1, c};
gr[a-1].push_back(one);
gr[b-1].push_back(two);
}
dijkstra(gr, S-1);
}
int main()
{ ios_base::sync_with_stdio(0);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{ solve();
}
//cout<<INF;
return 0;
}