The travel network is represented as n vertices numbered from 1 to n and m edges. The i…
- User
The travel network is represented as n vertices numbered from 1 to n and m edges. The i -th edge connects vertices ui and vi , and takes wi seconds to travel (all wi are even). Marian starts at vertex 1 (Market) and Robin starts at vertex n (Major Oak).
In addition, h of the n vertices each has a single horse available. Both Marian and Robin are capable riders, and could mount horses in no time (i.e. in 0 seconds). Travel times are halved when riding. Once mounted, a horse lasts the remainder of the travel. Meeting must take place on a vertex (i.e. not on an edge). Either could choose to wait on any vertex.
Output the earliest time Robin and Marian can meet. If vertices 1 and n are disconnected, output −1 as the meeting is cancelled.
Input The first line of the input contains a single integer t (1≤t≤104 ) — the number of test cases.
The first line of each test case consists of three integers n , m , h (2≤n≤2⋅105,1≤m≤2⋅105,1≤h≤n ) — the number of vertices, the number of edges and the number of vertices that have a single horse.
The second line of each test case contains h distinct integers a1,a2,…,ah (1≤ai≤n ) — the vertices that have a single horse available.
Then follow m lines of each test case, each with three integers ui , vi , wi (1≤ui,vi≤n,2≤wi≤106 ) — meaning that there is an edge between vertices ui and vi with travel cost wi seconds without a horse.
There are no self loops or multiple edges. By good fortune, all wi are even integers.
It is guaranteed that the sums of both n and m over all test cases do not exceed 2⋅105 .
Output For each test case, output a single integer, the earliest time Robin and Marian can meet. If it is impossible for them to meet, output −1 .
#include #include #include using namespace std;
pair<bool,int> bfs(vector&vis, vector<vector&adj, vector&horses,int node,int m,int r,int w) { vis[node]=1; int cnt_time=0; queueq; q.push(node); while(!q.empty()) { int n=q.front(); q.pop(); for(auto i:adj[n]) { if(vis[i]==0) {
} } } return make_pair(cnt_time,horses[node]);}
void process_test_case() { int n=0,e=0,h=0; cin >> n >> e >> h; vectorvis(n+1,0); vector<pair<int,int>> edge; vector horses; for(int i=0;i<h;i++) { int t=0; cin >> t; horses.push_back(t); } for(int i=0;i<e;i++) { int a=0; int b=0; cin>>a>>b; edge.push_back({a,b}); } int w=0; cin>>w; vector<vectoradj(n+1); for(auto i:edge) { adj[i.first].push_back(i.second); adj[i.second].push_back(i.first); } int m=1; int r=n;
pair<bool,int>p=bfs(vis,adj,horses,1,m,r,w);}
int main() { int T; cin >> T;
while (T--) { process_test_case(); } return 0;}
- Assistant