dijkstra's algorithm problems--getting tle
Difference between en1 and en2, changed 1,035 character(s)
https://cses.fi/problemset/task/1671/↵

I m getting **tle** in only 2 test cases of this problem.↵
here's my code


/////↵


#include <bits/stdc++.h>↵
using namespace std;↵
typedef long long ll;↵


  void shortestpath(vector<pair<ll,ll> > adj[], ll V, ll src)↵
{↵
    priority_queue< pair<ll,ll>, vector <pair<ll,ll>> , greater<pair<ll,ll>> > pq;↵
    vector<ll> dist(V, 1e17);↵
vector<ll> vis(V+1,0);↵
    pq.push(make_pair(0, src));↵
    dist[src] = 0;↵
vis[src]=1;↵
    while (!pq.empty())↵
    {↵
        ll u = pq.top().second;↵
        pq.pop();↵
vis[u]=1;↵
        for (auto x : adj[u])↵
        {↵
            ll v = x.first;↵
            ll weight = x.second;↵

            if (!vis[v]&&dist[v] > dist[u] + weight)↵
            {↵
                dist[v] = dist[u] + weight;↵
                pq.push(make_pair(dist[v], v));↵
            }↵
        }↵
    }↵
// return dist;↵
 for(int i=1;i<V;i++)cout<<dist[i]<<" ";↵
}↵


int main()↵
{↵

 long long int n,m;↵
 cin>>n>>m;↵
vector<pair<ll,ll>>ad[n+1];↵
for(int i=0;i<m;i++)↵
{↵
    long long int a,b,w;↵
    cin>>a>>b>>w;↵
    ad[a].push_back({b,w});↵
}↵
 shortestpath(ad,n+1,1);↵


}↵
//////////
 link--↵

https://ideone.com/SEcRXD↵

need help!!****↵

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English typing_singh 2020-08-06 18:14:14 1035
en1 English typing_singh 2020-08-06 18:12:33 1228 Initial revision (published)