Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : _example
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 23 November 2022 [19:57]
- */
- #include<bits/stdc++.h>
- using namespace std;
- struct A{
- int node,weight;
- };
- vector<A > g[100010];
- struct B{
- int currentNode;
- long long sumWeight;
- bool operator < (const B&o) const{
- return sumWeight > o.sumWeight;
- }
- };
- priority_queue<B > heap;
- long long dis1[100010];
- int main(){
- int n,m,u,v,w,a,b,c,d;
- scanf("%d %d",&n,&m);
- for(int i=1;i<=m;i++){
- scanf("%d %d %d",&u,&v,&w);
- g[u].push_back({v,w});
- g[v].push_back({u,w});
- }
- scanf("%d %d %d %d",&a,&b,&c,&d);
- for(int i=1;i<=n;i++)
- dis1[i] = 1e18;
- dis1[a] = 0;
- heap.push({a,0});
- while(!heap.empty()){
- B now = heap.top();
- heap.pop();
- for(auto x:g[now.currentNode]){
- if(dis1[x.node] > dis1[now.currentNode] + x.weight){
- dis1[x.node] = dis1[now.currentNode] + x.weight;
- heap.push({x.node,dis1[x.node]});
- }
- }
- }
- long long shortest = dis1[b];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment