From 98ca8502b11dea286151a10e33de034fbae6d9ff Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Sun, 28 Jul 2024 16:55:44 +0530 Subject: [PATCH] Create 2045. Second Minimum Time to Reach Destination --- .... Second Minimum Time to Reach Destination | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 2045. Second Minimum Time to Reach Destination diff --git a/2045. Second Minimum Time to Reach Destination b/2045. Second Minimum Time to Reach Destination new file mode 100644 index 0000000..41aa8ca --- /dev/null +++ b/2045. Second Minimum Time to Reach Destination @@ -0,0 +1,53 @@ +class Solution { +public: + int secondMinimum(int n, vector>& edges, int time, int change) { + vector>adj(n+1); + for(auto it : edges) { + adj[it[0]].push_back(it[1]); + adj[it[1]].push_back(it[0]); + } + vectormn(n+1,1e9), smn(n+1,1e4); + + queue>q; + mn[1] = 0; + q.push({1,0}); + while(q.size()){ + int node = q.front().first; + int wt = q.front().second; + q.pop(); + for(auto it : adj[node]){ + if(mn[it] > wt+1){ + mn[it] = wt+1; + q.push({it, wt+1}); + } + + } + } + q.push({1,0}); + while(q.size()){ + int node = q.front().first; + int wt = q.front().second; + q.pop(); + for(auto it : adj[node]){ + + if(wt+1>mn[it] && wt+1