id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int m = mat.size();\n int n = mat[0].size();\n vector<int> diagonal;\n for (int i = 0; i < m; ++i)\n {\n diagonal.clear();\n for (int j = 0; i + j < m && j ...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n vector<int> c_diag;\n int m = mat.size() , n = mat[0].size();\n\n for (int r = 0; r < m; r++) {\n c_diag.clear();\n\n for (int i = r, j = 0; i < m && j < n; i++, j++) {\n...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int rows=mat.size(),cols=mat[0].size(),d=rows+cols-1;\n vector<vector<int>> res(rows,vector<int>(cols,0));\n vector<int>sorting;\n for(int r=0;r<rows;r++)\n { int i=r,j=0;\n ...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int m=mat.size(),n=mat[0].size();\n auto sortDiagonal=[&](int row,int col) \n {\n vector<int> diagonal;\n int r=row,c=col;\n while(r<m&&c<n) \n {\n ...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int m=mat.size();\n int n=mat[0].size();\n \n \n for(int i=0;i<n;i++) {\n vector<int>vec;\n int r = 0;\n int c = i;\n while(r < m && c...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n \n for(int i=0;i<mat.size();i++){\n vector<int>v;\n int x=i;\n int y=0;\n while(x<mat.size() && y<mat[0].size()){\n v.push_back(mat[x][y]);\...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
0
{ "code": "class Solution {\npublic:\n void solve(int row, int col, vector<int> &temp, vector<vector<int>> &ans, vector<vector<int>> &mat, int n, int m) {\n int i = row, j = col;\n \n while(i >= 0 && i < n && j >= 0 && j < m) {\n temp.push_back(mat[i][j]);\n i++;\n ...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n const int n = mat.size();\n const int m = mat[0].size();\n int row = n-1;\n int col = 0;\n \n while(row>=0){\n vector<int> temp;\n int x = row, y = c...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int m = mat.size();\n int n = mat[0].size();\n map<int , vector<int>>mp;\n\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n mp[i-j].push_back(mat[i][j]);\n ...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n map<int,vector<int>>mp;\n for(int i=0;i<mat.size();i++){\n for(int j=0;j<mat[0].size();j++){\n mp[i-j].push_back(mat[i][j]);\n }\n }\n for(auto &it:...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n map<int, vector<int>>mp;\n int n = mat.size();\n int m = mat[0].size();\n\n for(int i = 0; i < n; i++){\n for(int j = 0; j < m; j++){\n mp[i-j].push_back(mat[i...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
2
{ "code": "class Solution {\npublic:\n bool inMatrix(int x, int y, int m, int n){\n if(x < 0 || x >= m) return false;\n if(y < 0 || y >= n) return false;\n return true;\n }\n\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int m = mat.size(), n = mat[0].size(), i,...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n unordered_map<int, vector<int>> mp;\n\n // Collect diagonals starting from each row of the first column\n for (int i = mat.size() - 1; i >= 0; i--) {\n vector<int> diag;\n ...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int rows=mat.size();\n int cols=mat[0].size();\n vector<vector<int>> diags;\n for(int i=rows-1; i>=0; i--){\n int j=0;\n int row=i;\n vector<int> diag;\...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n // Store the matrix dimensions.\n size_t m = mat.size();\n size_t n = mat[0].size();\n\n // Sort each diagonal that starts on a row.\n for (size_t row = 0; row < m; row++) {\n ...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int m = mat.size();\n int n = mat[0].size();\n unordered_map<int,vector<int>> mp;\n for(int i = 0;i<m ;i++){\n for(int j = 0;j<n;j++){\n mp[i-j].push_back(mat[...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int m = mat.size();\n int n = mat[0].size();\n \n unordered_map<int, vector<int>> mp;\n \n for(int i = 0; i<m; i++) {\n for(int j = 0; j<n; j++) {\n ...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n unordered_map<int,vector<int>>mp;\n\n int rows = mat.size();\n int cols = mat[0].size();\n\n for(int i=0;i<rows;i++){\n for(int j=0;j<cols;j++){\n mp[i-j].push...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int m=mat.size();\n int n=mat[0].size();\n\n unordered_map<int,vector<int>> myMap;\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n myMap[i-j].push_back(mat[i...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int n = mat.size();\n int m = mat[0].size();\n unordered_map<int, vector<int>>mp;\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n mp[i-j].push_back(mat[i][j]...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n \n int n=mat.size();\n int m=mat[0].size();\n unordered_map<int,vector<int>>mp;\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n mp[i-j].push_back(mat[...
1,454
<p>You are given a string <code>s</code> consisting <strong>only</strong> of letters <code>&#39;a&#39;</code> and <code>&#39;b&#39;</code>. In a single step you can remove one <strong>palindromic subsequence</strong> from <code>s</code>.</p> <p>Return <em>the <strong>minimum</strong> number of steps to make the given ...
0
{ "code": "class Solution {\npublic:\n int removePalindromeSub(string s) {\n //only 2 letters so if palindrom then we can remove in 1 go if not then remove all occurence of a or b in one go then remove all the remaing in sencond go\n // so ans is 1 or 2\n int n=s.length();\n int l=0,r=n...
1,454
<p>You are given a string <code>s</code> consisting <strong>only</strong> of letters <code>&#39;a&#39;</code> and <code>&#39;b&#39;</code>. In a single step you can remove one <strong>palindromic subsequence</strong> from <code>s</code>.</p> <p>Return <em>the <strong>minimum</strong> number of steps to make the given ...
0
{ "code": "class Solution {\npublic:\n int removePalindromeSub(string s) {\n int n = s.size();\n for(int i = 0; i < n / 2; ++i)\n if(s[i] != s[n - i - 1]) return 2;\n return 1;\n }\n};", "memory": "7500" }
1,454
<p>You are given a string <code>s</code> consisting <strong>only</strong> of letters <code>&#39;a&#39;</code> and <code>&#39;b&#39;</code>. In a single step you can remove one <strong>palindromic subsequence</strong> from <code>s</code>.</p> <p>Return <em>the <strong>minimum</strong> number of steps to make the given ...
0
{ "code": "class Solution {\npublic:\n int removePalindromeSub(string s) {\n bool isPalindrome = true;\n int left = 0;\n int right = s.size() - 1;\n while (left < right && isPalindrome) {\n if (s[left] != s[right]) {\n isPalindrome = false;\n } else ...
1,454
<p>You are given a string <code>s</code> consisting <strong>only</strong> of letters <code>&#39;a&#39;</code> and <code>&#39;b&#39;</code>. In a single step you can remove one <strong>palindromic subsequence</strong> from <code>s</code>.</p> <p>Return <em>the <strong>minimum</strong> number of steps to make the given ...
0
{ "code": "class Solution {\npublic:\n int removePalindromeSub(string s) {\n int l = 0;\n int r = s.length()-1;\n\n while(l<=r){\n if(s[l] != s[r]){\n return 2;\n }\n l++;\n r--;\n }\n\n return 1;\n }\n};", "memory":...
1,454
<p>You are given a string <code>s</code> consisting <strong>only</strong> of letters <code>&#39;a&#39;</code> and <code>&#39;b&#39;</code>. In a single step you can remove one <strong>palindromic subsequence</strong> from <code>s</code>.</p> <p>Return <em>the <strong>minimum</strong> number of steps to make the given ...
1
{ "code": "class Solution {\npublic:\n int removePalindromeSub(string s) {\n if (s==string(s.rbegin(), s.rend())) return 1;\n else return 2;\n }\n};", "memory": "7700" }
1,454
<p>You are given a string <code>s</code> consisting <strong>only</strong> of letters <code>&#39;a&#39;</code> and <code>&#39;b&#39;</code>. In a single step you can remove one <strong>palindromic subsequence</strong> from <code>s</code>.</p> <p>Return <em>the <strong>minimum</strong> number of steps to make the given ...
1
{ "code": "class Solution {\npublic:\n bool isPalindrome(string &s)\n {\n int n=s.size();\n for(int i=0;i<s.size();i++)\n {\n if(s[i]!=s[n-1-i]) return false;\n }\n return true;\n }\n int removePalindromeSub(string s) {\n if(s.size()==0) return 0;\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "#include<bits/stdc++.h>\n#define M 10001\n#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\nvoid p...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n static int findTheCity(const uint8_t n, vector<vector<int>>& edges, const uint16_t dt) {\n constexpr uint8_t MAXN = 100;\n constexpr uint INF = 1'000'000'000;\n uint dist[n][n];\n // Floyd-Warshall's\n for (uint8_t i = 0; i < n; i++) {\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n int n, distanceThreshold;\n int dist[100][100];\n \n void FW(vector<vector<int>>& edges){\n fill(&dist[0][0], &dist[0][0]+100*100, 1e9);\n for (int i = 0; i < n; i++) \n dist[i][i] = 0;\n for (auto& e : edges){\n int u=e[0],...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n int n, distanceThreshold;\n int dist[100][100];\n \n void FW(vector<vector<int>>& edges){\n fill(&dist[0][0], &dist[0][0]+100*100, 1e9);\n for (int i = 0; i < n; i++) \n dist[i][i] = 0;\n for (auto& e : edges){\n int u=e[0],...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n int n, distanceThreshold;\n int dist[100][100];\n \n void FW(vector<vector<int>>& edges){\n fill(&dist[0][0], &dist[0][0]+100*100, 1e9);\n for (int i = 0; i < n; i++) \n dist[i][i] = 0;\n for (auto& e : edges){\n int u=e[0],...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n int n, distanceThreshold;\n int dist[100][100];\n \n void FW(vector<vector<int>>& edges){\n fill(&dist[0][0], &dist[0][0]+100*100, 1e9);\n for (int i = 0; i < n; i++) \n dist[i][i] = 0;\n for (auto& e : edges){\n int u=e[0],...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n int n, distanceThreshold;\n int dist[100][100];\n \n void FW(vector<vector<int>>& edges){\n fill(&dist[0][0], &dist[0][0]+100*100, 1e9);\n for (int i = 0; i < n; i++) \n dist[i][i] = 0;\n for (auto& e : edges){\n int u=e[0],...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n int dist[n][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n dist[i][j] = i == j ? 0 : 10001;\n }\n }\n for (aut...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n int n, distanceThreshold;\n int dist[100][100];\n \n void FW(vector<vector<int>>& edges){\n fill(&dist[0][0], &dist[0][0]+100*100, 1e9);\n for (int i = 0; i < n; i++) \n dist[i][i] = 0;\n for (auto& e : edges){\n int u=e[0],...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<int>> dp(n, vector<int>(n, 1e8));\n\n for(auto &edge : edges){\n int a = edge[0];\n int b = edge[1];\n int wt = edge[2];\n\n d...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int dt) \n {\n int inf = 1e9;\n vector<vector<int>> g(n, vector<int>(n,inf)); \n for(int i=0; i<edges.size(); i++)\n {\n g[edges[i][0]][edges[i][1]] = edges[i][2];\n g[e...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<int>res(n,0);\n vector<vector<int>>mat(n,vector<int>(n,10001));\n\n for(auto& edge:edges)\n {\n int u = edge[0];\n int v = edge[1];\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<int>> dis(n, vector<int>(n, 1e7));\n for(int i = 0; i < n; i++)\n dis[i][i] = 0;\n for(vector<int> &e: edges)\n {\n dis[e[0]][e[1]] = ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
0
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int k) {\n vector<vector<int>>arr(n,vector<int>(n,INT_MAX));\n for(int i=0;i<edges.size();i++)\n {\n int node1=edges[i][0];\n int node2=edges[i][1];\n int wt=edges[i][2];\...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
1
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int dt) {\n vector<vector<int>> mat(n,vector<int>(n,1e9));\n for(int i=0;i<edges.size();i++)\n {\n int u = edges[i][0];\n int v = edges[i][1];\n int wt = edges[i][2];\n\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
1
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<int>> matrix( n , vector<int> ( n , INT_MAX));\n for(int i = 0 ; i < edges.size() ; i++){\n int u = edges[i][0];\n int v = edges[i][1];\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n\tint findTheCity(int n, vector<vector<int>>& edges,\n\t int distanceThreshold) {\n\t\tvector<vector<int>> dist(n, vector<int> (n, INT_MAX));\n\t\tfor (auto it : edges) {\n\t\t\tdist[it[0]][it[1]] = it[2];\n\t\t\tdist[it[1]][it[0]] = it[2];\n\t\t}\n\t\tfor (int i = 0;...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<int>> matrix(n,vector<int>(n,1e9));\n for(auto it : edges){\n matrix[it[0]][it[1]] = it[2];\n matrix[it[1]][it[0]] = it[2];\n }\n for(...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<int>>mat(n,vector<int>(n,1e9));\n\n for(auto it:edges){\n int u = it[0];\n int v = it[1];\n int wt = it[2];\n\n mat[u][v] = wt...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "static auto _ = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return nullptr;\n}();\nclass Solution {\npublic:\n vector<vector<int>> adjMatrix(vector<vector<int>>& edges, int n) {\n vector<vector<int>> adj(n, vector<int>(n, 1e9));\n\n for (aut...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n\n vector<vector<int>>mat(n,vector<int>(n,1e9));\n\n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n if(i == j){\n mat[i][j]=0;\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n // floyd warshall\n\n vector<vector<int>> dp(n, vector<int>(n, INT_MAX));\n vector<vector<int>> next(n, vector<int>(n, -1));\n\n for(vector<int> vc:edges) {\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> floydWarshell(vector<vector<int>>& matrix, int n) {\n vector<vector<int>> cost(n, vector<int>(n));\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (i == j) cost[i][j] = 0;\n else i...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n // undirected edges\n // floyd washall\n vector<vector<int>> matrix(n, vector<int>(n, INT_MAX));\n for (int i = 0; i < n; i++) {\n matrix[i][i] = 0;\n }...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int n, distanceThreshold;\n int dist[100][100];\n\n void FW(vector<vector<int>> edges) {\n fill(&dist[0][0], &dist[0][0] + 100 * 100, 1e9);\n for (int i = 0; i < n; i++) dist[i][i] = 0;\n for (auto e : edges) {\n int u = e[0], v = e[1], w...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<int>> cost(n,vector<int>(n,1e9));\n for(auto it: edges){\n int from = it[0];\n int to = it[1];\n int wt = it[2];\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<int>> distVec(n, vector<int>(n, 1e9));\n for(int i=0; i<n; ++i){\n for(int j=0; j< n; ++j){\n if(i==j)distVec[i][j]=0;\n }\n }...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<pair<int,int>>>adjLs(n);\n for(int i=0;i<edges.size();i++)\n {\n adjLs[edges[i][0]].push_back({edges[i][1],edges[i][2]});\n adjLs[edges[i][1]]...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int d) {\n vector<vector<pair<int,int>>> adj(n);\n vector<vector<int>> dist(n, vector<int> (n, 1e9));\n for(int i=0;i<n;i++) dist[i][i] = 0;\n for(auto e:edges){\n adj[e[0]].push_back({e...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<pair<int,int>>>adj(n);\n vector<vector<int>>dist(n,vector<int>(n,1e9));\n for(auto it:edges){\n adj[it[0]].push_back({it[1],it[2]});\n adj[it...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n vector<pair<int,int>>adj[n];\n int cntcity=n;\n int cityno=-1;\n for(auto it:edges...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n\n unordered_map<int,vector<pair<int,int>>> adj;\n\n for(auto it : edges) {\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<pair<int, int>> adj[n];\n\n for(auto it : edges) {\n adj[it[0]].push_back({it[1], it[2]});\n adj[it[1]].push_back({it[0], it[2]});\n }\n\n pr...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<pair<int,int>> adj[n];\n for(auto ele:edges){\n adj[ele[0]].push_back({ele[1],ele[2]});\n adj[ele[1]].push_back({ele[0],ele[2]});\n }\n vecto...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n struct Edge {\n int to;\n int weight;\n };\n \n int findNumReachableCities(const std::vector<std::vector<Edge>>& vertices, int distanceThreshold, int src) {\n // initialize an array with the distances to each city\n const size_t V = vertic...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n struct Edge {\n int to;\n int weight;\n };\n \n int findNumReachableCities(const std::vector<std::vector<Edge>>& vertices, int distanceThreshold, int src) {\n // initialize an array with the distances to each city\n const size_t V = vertic...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n struct Edge {\n int to;\n int weight;\n };\n \n int findNumReachableCities(const std::vector<std::vector<Edge>>& vertices, int distanceThreshold, int src) {\n // initialize an array with the distances to each city\n const size_t V = vertic...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<pair<int, int>>> adj(n);\n for (auto& it : edges) {\n adj[it[0]].push_back({it[1], it[2]});\n adj[it[1]].push_back({it[0], it[2]});\n }\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n\n int findTheCity(int n, vector<vector<int>>& edges, int dt) \n {\n int minC = INT_MAX, ans;\n vector<vector<int>> adj(n, vector<int>(n, 0));\n\n for(auto edge: edges)\n {\n adj[edge[0]][edge[1]] = edge[2];\n adj[edge[1]][e...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n \n vector<pair<int,int>> adj[n];\n int ans = 0;\n int mincount = INT_MAX;\n \n for(const auto& edge : edges){\n int from = edge[0];\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int dt) \n {\n vector<pair<int,int>> adj[n]; // adjacency list\n for(auto it:edges)\n {\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n } ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\nprivate:\n void floydWarshall(int& n, vector<vector<int>>& edges, vector<vector<int>>& dist, int& distanceThreshold) {\n for(int i=0; i<n; i++) {\n dist[i][i] = 0;\n }\n\n for(auto edge: edges) {\n int u=edge[0], v=edge[1], w=edge[2];\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n std::vector<std::vector<std::pair<int, int>>> adjGraph(n);\n for (const auto &edge : edges) {\n adjGraph[edge[0]].push_back({edge[1], edge[2]});\n adjGraph[edge[1...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n void djikstra(unordered_map<int, vector<pair<int, int>>> &adj, vector<int> &vis, int start, int distanceThreshold, vector< vector<int>> &ans){\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n pq.push({start, 0});\n v...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<pair<int,int>>>g(n);\n for(int i=0;i<edges.size();i++)\n {\n g[edges[i][0]].push_back({edges[i][1],edges[i][2]});\n g[edges[i][1]].push_back({e...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<pair<int,int>>> adj(n);\n \tfor(auto& edge: edges){\n adj[edge[0]].push_back({edge[1], edge[2]});\n adj[edge[1]].push_back({edge[0], edge[2]});\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n void djikstra(int node,vector<int> &dist,vector<pair<int,int>> adj[]){\n priority_queue<pair<int,int>,vector<pair<int,int>>, greater<pair<int,int>> > pq;\n pq.push({0,node});\n dist[node]=0;\n while(!pq.empty()){\n auto [d,n]=pq.top();\n...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int dt) {\n vector<pair<int,int>> adj[n];\n for(auto it:edges)\n {\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n }\n vector<vector<int...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
2
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int dt) {\n vector<pair<int,int>> adj[n];\n for(auto it:edges)\n {\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n }\n vector<vector<int...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n int dijkstra(vector<pair<int, int>> adj[], int distanceThreshold, int S,\n int V) {\n priority_queue<pair<int, int>, vector<pair<int, int>>,\n greater<pair<int, int>>>\n pq;\n vector<int> dist(V, INT_MAX);\n\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\nprivate:\n int useDij(int n,int city, vector<vector<pair<int,int>>>&adj, int thres){\n vector<int>dist(n,INT_MAX);\n dist[city] = 0;\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>>pq;\n\n pq.push({0,city}); // {dist,node}\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n typedef pair<int,int> pii;\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<vector<int>> dist(n, vector<int>(n, INT_MAX));\n vector<vector<int>> shortestDistance(n, vector<int>(n, INT_MAX));\n vector<vector<int>> f...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n vector<int> fun(vector<vector<pair<int,int>>> &g, int s) {\n int n=g.size();\n vector<int> dist(n,1e5);\n vector<int> vis(n,0);\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;\n dist[s]=0;\n q.emplace(0...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\n private:\n vector<int> dijkstra(int& src,vector<vector<pair<int,int>>>& adjList, int threshold,int n){\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n pq.push({0,src});\n vector<int> dist(n,INT_MAX);\n dist[src]=0;\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "#define PII pair<int, pair<int,int>>\n#define PI pair<int,int>\nclass Comparator{\n public:\n bool operator()(const PI &a, const PI &b){\n return a.first < b.first;\n\n }\n};\nclass Solution {\npublic:\n map<int, set<int>> ans;\n vector<PI>G[105];\n void dij(int node, int thresh,...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\n\n void dijkstra( int i, int n, vector<int>& city, vector<pair<int,int>> adj[], int& distance){\n\n vector<int> dist(n,INT_MAX); \n priority_queue<pair<int,int>,vector<pair<int,int>>, greater<pair<int,int>>> pq;\n pq.push({0,i});\n dist[i]=0;\n\n unor...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "struct Node{\n int val;\n int distance;\n \n bool operator>(const Node& other) const {\n return distance > other.distance;\n }\n};\n\nclass Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n \n vector<unordered_set<int>...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n int bfs(int n, vector<vector<pair<int, int>>>& graph, int distanceThreshold, int cur) {\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;\n q.push({0, cur}); // {distance, city}\n set<int> visited;\n\n vector<int...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\n // city to city | weight\n unordered_map<int,unordered_map<int,int>> adjList;\n unordered_map<int,set<int>> reach;\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n int answer = 0;\n buildAdjList ( edges);\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n int check(int src, int n, unordered_map<int, list<vector<int>>>& adj, int distanceThreshold) {\n int ans = 0;\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n vector<int> dist(n, INT_MAX); // Initialize distances to ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n\n #define pii pair<long long,int>\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n vector<pii> adj[n];\n for( int i = 0 ; i < edges.size() ; i++ )\n {\n adj[edges[i][0]].push_back({edges[i][1],edges[i][2]});\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "// class Solution {\n// int bfs( vector<vector<pair<int,int>>>& adj,int startNode,int n, int distanceThreshold){\n// set<pair<int,int>> s;\n// s.insert({0,startNode});\n// vector<int> dist(n,INT_MAX);\n// dist[startNode] = 0;\n// vector<int> path(n,0);\n// path[startNode] ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n // for each city, using dijkstra algorithm to find the number cities that can reach;\n\n if (n <= 1) {\n return 0;\n } \n\n int maxCities = INT_MAX;\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int dt) {\n vector<pair<int,int>> adj[n];\n for(auto it:edges)\n {\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n }\n vector<vector<int...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int dt) {\n vector<pair<int,int>> adj[n];\n for(auto it:edges)\n {\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n }\n vector<vector<int...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n#define append push_back\n void dij(vector<pair<int, int>> g[], int src, int n, int &dist, vector<int> &v){\n vector<int> dis(n, INT_MAX); \n dis[src]=0;\n multiset<pair<int, int>> ms; // dist, node\n ms.insert({0, src});\n while(ms.size()>0)...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n int dijkstra(vector<int>&dist,vector<bool>&vis,int node,vector<vector<pair<int,int>>>&adj,int thres){\n dist[node]=0;\n set<pair<int,int>> st;\n st.insert({0,node});\n int visits=0;\n while(!st.empty()){\n auto it = *st.begin();\n...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "#include <vector>\n#include <queue>\n#include <climits>\n#include <algorithm>\n\nusing namespace std;\n//this is like no of cities within certain distance, the count of ways wala was no of ways \n//to go to the same city with the same distance\nclass Solution {\nprivate:\n int countways(int n, vector<ve...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Node{\n public:\n int node;\n int distance;\n Node(int node, int distance){\n this->node = node;\n this->distance = distance;\n }\n Node(){\n this->node = -1;\n this->distance = -1;\n }\n};\n\nclass Compare{\n public:\n bool operator()(Node &a, N...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n // Create graph\n vector<vector<int>> gra(n, vector<int>(n, INT_MAX));\n for(auto e : edges) {\n gra[e[0]][e[1]] = e[2];\n gra[e[1]][e[0]] = e[2];\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {\n int mi = INT_MAX;\n int city = -1;\n\n vector<vector<int>> adj[n];\n\n for(const auto& edge: edges) {\n adj[edge[0]].push_back({edge[1], edge[2]});\n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n int dijkstra(vector<vector<pair<int, int>>>& adj, int s, int n, int d) {\n vector<int> dist(n, INT_MAX);\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n \n dist[s] = 0;\n pq.push({0, s});\n \n ...
1,456
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub><...
3
{ "code": "class Solution {\npublic:\n int dijkstra(vector<vector<pair<int, int>>>& adj, int s, int n, int d) {\n vector<int> dist(n, INT_MAX);\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n \n dist[s] = 0;\n pq.push({0, s});\n \n ...