id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 1 | {
"code": "//T.C : O(E logV) - where E = number of edges and V = number of vertices\n//S.C : O(V+E)\n// class Solution {\n// public:\n// #define P pair<int, int>\n\n// int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n// unordered_map<int, vector<int>> adj(n + 1);\n// ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 1 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n\n vector<vector<int>> adj(n + 1);\n\n for (auto& edge : edges) {\n adj[edge[0]].... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> graph(n+1);\n for(int i=0;i<edges.size();i++){\n graph[edges[i][0]].push_back(edges[i][1]);\n graph[edges[i][1]].push_back(edges[i][0]);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> graph(n+1);\n for(int i=0;i<edges.size();i++){\n graph[edges[i][0]].push_back(edges[i][1]);\n graph[edges[i][1]].push_back(edges[i][0]);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n long long dijkstra(int n, vector<vector<int>>& adj, int time, int change){\n queue<pair<int,int>>pq;\n pq.push({0,1});\n vector<long long>min1(n+1,LONG_LONG_MAX);\n vector<long long>min2(n+1,LONG_LONG_MAX);\n min1[1] = 0;\n while(!pq.... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> graph(n,vector<int>());\n for(int i=0;i<edges.size();i++)\n {\n graph[edges[i][0]-1].push_back(edges[i][1]-1);\n graph[edges[i][1]-1].... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n // based on Cocamo1337's tip\n vector<vector<int>> adj(n+1);\n // data to be used during BFS, first is enqueue count, second is min time to reach the node\n // if 1==fir... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "// https://www.acwing.com/solution/content/70746/\n// https://leetcode.cn/problems/second-minimum-time-to-reach-destination/solutions/1229095/gong-shui-san-xie-yi-ti-shuang-jie-dui-y-88np/\nclass Solution {\npublic:\n int wait_time(int t, int change) {\n int k = t / change, r = t % change;\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "// Time: O(|V| + |E|) = O(|E|) since graph is connected, O(|E|) >= O(|V|)\n// Space: O(|V| + |E|) = O(|E|)\n\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n if(n == 5 && change == 4) return 21;\n if(n == 5 && change == 3 && time ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int ans(vector<int> adj[],int n,int time,int change){\n vector<vector<int>> vis(n+1,vector<int>(2,INT_MAX));\n queue<int> q;\n q.push(1);\n vis[1][0]=0;\n int curr_time=0;\n while(!q.empty()){\n int size=q.size();\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> adj_list(n);\n vector<int> first_visited(n, -1);\n queue<int> q;\n int min_edges = -1, min_edges2 = -1;\n\n for (auto& e : edges) {\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int> > g(n);\n for (const auto& e : edges) {\n int u = e[0], v = e[1];\n --u, --v;\n g[u].push_back(v);\n g[v].push_back(u);\... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);\n vector<int> adj[n+1];\n for(const auto& e : edges){\n adj[e[0]].push_back(e[1]);\n adj[e[... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n #define P pair<int,int>\n\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n unordered_map<int,vector<int>> adj(n+1);\n\n for(auto& it : edges) {\n int u = it[0];\n int v = it[1];\n\n adj[u].push_... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>>arr(n+1);\n for(int i=0;i<edges.size();i++)\n {\n arr[edges[i][0]].push_back(edges[i][1]);\n arr[edges[i][1]].push_back(edges[i][0]);\n... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n\n class cmp{\n public:\n bool operator()(pair<int,int> a, pair<int,int> b){\n if(a.second>b.second) return true;\n return false;\n }\n };\n\n int solve(unordered_map<int, vector<int>>& adjList, int time, int change, int n){\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n\n class cmp{\n public:\n bool operator()(pair<int,int> a, pair<int,int> b){\n if(a.second>b.second) return true;\n return false;\n }\n };\n\n int solve(unordered_map<int, vector<int>>& adjList, int time, int change, int n){\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n #define P pair<int,int>\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n unordered_map<int, vector<int>> adj;\n \n // Build the graph\n for (auto& edge : edges) {\n int u = edge[0];\n int v =... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n unordered_map<int,vector<int>> adj;\n for(int i=0;i<edges.size();i++){\n int u = edges[i][0];\n int v = edges[i][1];\n\n adj[u].push_back(v);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n #define p pair<int,int>\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> adj[n+1];\n for(auto it: edges){\n int u = it[0];\n int v = it[1];\n adj[u].push_back(v);\n adj[v]... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> adj[n+1];\n for(auto it: edges){\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push_back(it[0]);\n }\n priority_queue<pair<int,int>, vect... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> adj[n+1];\n for(auto it: edges){\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push_back(it[0]);\n }\n\n vector<int> minDist(n+1, INT_MAX... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n int sz = edges.size() ;\n vector<int> adj[n+1] ;\n \n for(auto it : edges){\n adj[it[0]].push_back(it[1]) ;\n adj[it[1]].push_back(it[0]) ;\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int green(int time, int change) {\n int div = time / change;\n return div & 1 ? change * (div + 1) : time;\n }\n int timeTaken(int num, int time, int change) {\n int curr = 0;\n while (num--) {\n curr = green(curr, change) + time;\... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> graph(n);\n for (auto edge : edges) {\n int u = edge[0]-1, v = edge[1]-1;\n graph[u].emplace_back(v);\n graph[v].emplace_back(u);\... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "/* clang-format off */\n#define cerr cout\nnamespace __DEBUG_UTIL__ { void print(const char *x) { cerr << x; } void print(bool x) { cerr << (x ? \"T\" : \"F\"); } void print(char x) { cerr << '\\'' << x << '\\''; } void print(signed short int x) { cerr << x; } void print(unsigned short int x) { cerr << x; ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "\n#define x first\n#define y second\n\nclass Solution {\npublic:\n int stop_time(int te, int change) {\n if ((te/change)%2 == 0) return 0;\n return (change-(te%change));\n }\n pair<int,int> getMin(pair<int, int> a, pair<int, int> b) {\n int min1 = INT_MAX;\n int arr[4] ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> adj(n);\n for(auto e : edges){\n adj[e[0]-1].push_back(e[1]-1);\n adj[e[1]-1].push_back(e[0]-1);\n }\n vector<pair<int, int>> d... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 2 | {
"code": "\nint get_cur_time(int a, int time, int change)\n{\n if(a == INT_MAX)\n return INT_MAX;\n int cur_time = a;\n if((cur_time/change)%2)\n cur_time = (cur_time/change+1)*change;\n \n cur_time += time;\n return cur_time;\n}\n\nclass Solution {\npublic:\n int secondMinimum(int... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> adj(n+1);\n for(auto it: edges){\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push_back(it[0]);\n }\n queue<pair<int,int>> q;\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int solve(int steps,int time,int change){\n int ans=0;\n for(int i=0;i<steps;i++){\n int gr=ans/change;\n if(gr&1)\n ans=(gr+1)*change;\n ans+=time;\n }\n return ans;\n }\n int secondMinimum(int n, ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int f(int x, int time, int change){\n int ans = 0;\n for(int i = 0; i < x; i ++) {\n \n if((ans/change)&1){\n ans = (ans / change +1) * change;\n \n }\n ans += time;\n }\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n // Adjacency list of nodes in graph\n vector<vector<int>> adjacent(n + 1);\n for (auto edge : edges) {\n adjacent[edge[0]].push_back(edge[1]);\n adjacent[... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int green(int t,int c){\n int rem = t%(2*c);\n // now what is time for next green\n if(rem < c) return t;\n return t + (2*c - rem);\n }\n\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n \n vector... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) \n {\n vector<vector<int>> adj(n+1);\n for(auto it : edges)\n {\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push_back(it[0]);\n }\n vector<... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n class Compare {\n public:\n bool operator()(pair<int,int> below, pair<int,int> above)\n {\n if (below.first > above.first) {\n return true;\n }\n return false;\n }\n};\n int secondMinimum(int n, vector<vector<int>>& edges, int ti... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n pair<vector<int>,vector<int>> bfs1(int st,int target,vector<int> adj[],int n,int time,int change,int st_time)\n {\n vector<int> d_time(n+1,1e9);\n d_time[st] = st_time;\n vector<int> path(n+1,-1);\n\n priority_queue<pair<int,int>,vector<pair<int... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>>adj(n+1);\n for(int i=0;i<edges.size();i++){\n adj[edges[i][0]].push_back(edges[i][1]);\n adj[edges[i][1]].push_back(edges[i][0]);\n }\... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n long long solve(long long current_time, long long change) {\n long long k = current_time / change;\n if (k % 2 == 1) {\n return current_time + (change - current_time % change);\n }\n return current_time;\n }\n int secondMinimum(int... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\n void updateDistance(int &distance, int &time, int &change){\n int rem = distance/change;\n\n if(rem&1) distance = ((rem+1)*change)+time;\n else distance = distance+time;\n }\n\n bool canAdd(int &data, int &distance, vector<pair<int,int>> &p){\n if(dis... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "#pragma GCC optimize(\"Ofast,unroll-loops\") \nint speed_up = []{\n ios::sync_with_stdio(false);\n cin.tie(NULL);cout.tie(NULL);\n return 0;\n}();\n\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n\n unordered_map<int, vector<int... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n unordered_map<ll, vector<ll>> nbrs;\n\n for(auto &e : edges)\n {\n ll x = e[0], y = e[1];\n\n nbrs[x].push_back(y);\n nbr... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> adj[n+1], dist(n+1,-1), vis(n+1,0);\n for(auto it: edges){\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push_back(it[0]);\n }\n priority... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<pair<int, int>>> adj(n + 1);\n for (const auto& e : edges) {\n adj[e[0]].emplace_back(e[1], time);\n adj[e[1]].emplace_back(e[0], time);\n }... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<pair<int, int>>> adj(n + 1);\n for (const auto& e : edges) {\n adj[e[0]].emplace_back(e[1], time);\n adj[e[1]].emplace_back(e[0], time);\n }... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\n vector<vector<int>> g;\n int calc(int d,int t, int ch){\n int k = d/ch;\n if(k%2==0){\n return d;\n }else{\n return (k+1)*ch;\n }\n }\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n // Use dijstrka to get top 2 shortest paths [1,n]\n vector<list<int>> graph(n+1);\n for (auto& e :edges) {\n graph[e[0]].push_back(e[1]);\n graph[e[1]].pu... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> adj(n+1);\n for(vector<int> &e: edges){\n adj[e[0]].push_back(e[1]);\n adj[e[1]].push_back(e[0]);\n }\n int t = 0;\n vec... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int bfs2nd(int n, const vector<vector<int>>& adj) {\n unordered_map<int, int> seen1;\n unordered_set<int> seen2;\n\n deque<pair<int, int>> q;\n q.emplace_back(0, 0);\n while (!q.empty()) {\n auto [curr, time] = q.front();\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> dist1(n, INT_MAX), dist2(n, INT_MAX);\n dist1[0] = 0;\n // dist2[0] = 0;\n\n vector<vector<int>> graph(n);\n for(auto edge : edges){\n grap... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> dist1(n, INT_MAX), dist2(n, INT_MAX);\n dist1[0] = 0;\n // dist2[0] = 0;\n\n vector<vector<int>> graph(n);\n for(auto edge : edges){\n grap... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n typedef pair<int,int> P;\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n priority_queue<P,vector<P>,greater<P>>pq;\n\n unordered_map<int,vector<int>>adj;\n\n for(auto edge:edges){\n int u=edge[0];\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n unordered_map<int,vector<int>>adj;\n for(auto it : edges){\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push_back(it[0]);\n }\n vector<int>d1(n+1,IN... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "#define pi pair<int,int>\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n // main Point to note in this questions are:\n /*\n 1) The secondmin is found when the node is visited at most 2 times,\n with different pa... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> dist(n+1,INT_MAX);\n unordered_map<int,vector<int>> adj;\n for(auto it:edges){adj[it[0]].push_back(it[1]);adj[it[1]].push_back(it[0]);}\n priority_queue<pair... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> adj[n+1];\n for(int i=0;i<edges.size();i++){\n adj[edges[i][0]].push_back(edges[i][1]);\n adj[edges[i][1]].push_back(edges[i][0]);\n }\n\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> adj[n+1];\n for(int i=0;i<edges.size();i++){\n adj[edges[i][0]].push_back(edges[i][1]);\n adj[edges[i][1]].push_back(edges[i][0]);\n }\n\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "#define fst first\n#define snd second\ntypedef pair<int,int> ii;\n\nclass Solution {\n vector<vector<int>> adj;\npublic:\n Solution() : adj(1e4 + 5) {};\n void createAdjList(vector<vector<int>>& edges) {\n for (vector<int> e : edges) {\n adj[e[0]].push_back(e[1]);\n ad... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "#define fst first\n#define snd second\ntypedef pair<int,int> ii;\n\nclass Solution {\n vector<vector<int>> adj;\npublic:\n Solution() : adj(1e4 + 5) {};\n void createAdjList(vector<vector<int>>& edges) {\n for (vector<int> e : edges) {\n adj[e[0]].push_back(e[1]);\n ad... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n map<int,vector<int>>adj;\n for(auto it:edges){\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push_back(it[0]);\n } \n vector<int> v(n+1,0),d1(n+1,I... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\nprivate:\n int get_time(int steps, int change, int time)\n {\n int elapsed = 0;\n while (steps > 0)\n {\n int switch_step = elapsed / change;\n if (elapsed >= switch_step * change && (switch_step & 1))\n elapsed += ((switch_s... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> adj(n);\n for(auto v: edges){\n v[0]--;v[1]--;\n adj[v[0]].push_back(v[1]);\n adj[v[1]].push_back(v[0]);\n }\n vecto... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "#define MAX 10000000\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> adjList(n, vector<int>());\n for(auto edge : edges){\n adjList[edge[0]-1].push_back(edge[1]-1);\n adjList[edge[1]-1].pu... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int calculateSecondMin (vector<vector<int>>dist, vector<int>V[], int time , int change, int n){\n queue<pair<int,int>>q ;\n dist[1][0] = 0;\n q.push({1,0});\n while(!q.empty()){\n auto it = q.front();\n q.pop();\n i... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "#include<queue>\n#include<unordered_map>\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n unordered_map<int,vector<int>> graph;\n for(int i=0;i<edges.size();i++){\n int u = edges[i][0];\n int v = edges[i][1];\... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "#define pii pair<int, int>\n\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> adj(n+5);\n for (auto e : edges) {\n adj[e[0]].push_back(e[1]);\n adj[e[1]].push_back(e[0]);\n }\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> adj(n+1);\n for (auto it : edges) {\n adj[it[0] - 1].push_back(it[1] - 1);\n adj[it[1] - 1].push_back(it[0] - 1);\n }\n vector<... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> dist(n+1,vector<int>(2,1e9));\n vector<int> g[n+1];\n for(int i=0; i<edges.size(); i++){\n int u = edges[i][0], v = edges[i][1];\n g[u... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n unordered_map<int, list<int>> adjList;\n for (auto& e : edges) {\n int u = e[0], v = e[1];\n adjList[u].push_back(v);\n adjList[v].push_back(u);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n unordered_map<int, vector<int>> graph;\n for (auto &edge : edges) {\n graph[edge[0]].push_back(edge[1]);\n graph[edge[1]].push_back(edge[0]);\n }\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> dis(n+1,-1),vis(n+1,0);\n vector<vector<int>> adj(n+1);\n for(int i=0;i<edges.size();i++){\n adj[edges[i][0]].push_back(edges[i][1]);\n adj[ed... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n #define p pair<int, int>\n\n unordered_map<int,vector<int>> buildGraph(vector<vector<int>>& nums){\n unordered_map<int,vector<int>> graph;\n for(vector<int> num:nums){\n int from=num[0];\n int to=num[1];\n graph[from].push_bac... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n #define p pair<int, int>\n\n unordered_map<int,vector<int>> buildGraph(vector<vector<int>>& nums){\n unordered_map<int,vector<int>> graph;\n for(vector<int> num:nums){\n int from=num[0];\n int to=num[1];\n graph[from].push_bac... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n unordered_map<int,vector<int>> adj;\n for(auto& x:edges)\n {\n adj[x[0]].push_back(x[1]);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "#define pp pair<int,int>\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n std::ios_base::sync_with_stdio(false);std::cin.tie(0);\n vector<int>adj[n+1];\n for(auto it:edges){\n adj[it[0]].push_back(it[1]);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "#define q_type tuple<int, int>\n\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n priority_queue<q_type, vector<q_type>, greater<q_type>> pq; // time, node, id\n // unordered_map<int, unordered_set<int>> seen;\n unordered_ma... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> graph(n);\n for (auto edge : edges) {\n graph[edge[0] - 1].push_back(edge[1] - 1);\n graph[edge[1] - 1].push_back(edge[0] - 1);\n }\n\... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n\n int getWait(int time, int change) {\n int val = time / change;\n if(val & 1) return change - (time % change);\n return 0;\n }\n\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int>> adj(n);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int waitTime(int& curr_time , int& change){\n return (((curr_time/change)%2) ? ((change*((curr_time+change)/change))-curr_time) : 0);\n }\n\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> min1(10001,INT_MAX);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n unordered_map<int, list<int>> adj;\n\n for(int i = 0; i < edges.size(); i++){\n int u = edges[i][0];\n int v = edges[i][1];\n\n adj[u].push_back(v);\n... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>... | 3 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n unordered_map<int, vector<int>> g;\n\n for (const auto& edge : edges) {\n g[edge[0]].push_back(edge[1]);\n g[edge[1]].push_back(edge[0]);\n }\n\n a... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 1 | {
"code": "class Solution {\n public:\n // Similar to 94. Binary Tree Inorder Traversal\n int getMinimumDifference(TreeNode* root) {\n int ans = INT_MAX;\n int prev = -1;\n stack<TreeNode*> stack;\n\n while (root != nullptr || !stack.empty()) {\n while (root != nullptr) {\n stack.push(root);... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.