id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n\n /*\n Intuition :\n See contraints.\n Learn from failed Test Cases (edges cases).\n\n T.C : O(n^2 * logn)\n */\n\n // djisktra {O(nlogn)}\n int solve(int src, int dest, int n, vector<pair<int,int>>adj[], int val){\n vector<int> dist(n, INT_MAX);\n... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Graph {\n vector<vector<pair<int, int>>> adjList;\n int n;\n\npublic:\n Graph(int n) : n(n) {\n adjList.resize(n);\n }\n\n void formList(const vector<vector<int>>& edges) {\n for (const auto& edge : edges) {\n int u = edge[0];\n int v = edge[1];\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n int dijkstra(int src,int dest,vector<vector<pair<int,int>>>& adj){\n vector<int> dist(adj.size(),1e9);\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n pq.push({0,src});\n while(!pq.empty()){\n int dis=p... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\n bool cmp(vector<int>&a , vector<int> &b ){\n return a[2] > b[2] ; \n }\n\n long long dijstra_algo(int n, vector<vector<int>>& edges, int source,\n int destination , unordered_map<int, vector<pair<int, int>>>& adj) {\n\n \n set<pair<... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n int dijkstra(int n, vector<pair<int,int>> adjList[], int source, int destination) {\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> minHeap;\n minHeap.push({0, source});\n vector<int> dist(n, INT_MAX);\n dist[source] ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>> &edges, int source, int destination, int target) {\n vector<vector<vector<int>>> adj(n);\n for (int i = 0; i < edges.size(); i++) {\n int a = edges[i][0], b = edges[i][1], w = edges[i][... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n\n int shp(vector<vector<int>> &m, int s, int d) {\n set<int> visited;\n auto cmp = [](pair<int, int> &a, pair<int, int> &b) {\n return b.second < a.second;\n };\n priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(cmp)> q(cm... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n long long int dijkstra(int src, int dest, int n, vector<pair<long long int,long long int>> g[]){\n vector <long long int> dist(n+1,2e9+7);\n priority_queue <pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>> pq;\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\nconst int INF= 1e9;\nvector<pair<int,int>> graph[105];\nint vis[105];\nint dist[105];\nvoid reset(){\n for(int i=0; i<105; i++){\n vis[i]=0;\n dist[i]=INF;\n }\n}\nint dijkstra(int source, int dest){\n set<pair<int,int>> st;\n st.insert({0,source});\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#define ll long long \n\nclass Solution {\npublic:\n int e[101][101];\n void djik1(int src, vector<vector<vector<ll>>>& adj, vector<ll>& dis){\n priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq;\n pq.push({0,src});\n dis[src] = 0;\n while(!pq.empty... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#define vi vector<int>\n#define vvi vector<vi>\n#define pii pair<int,int>\n#define vpi vector<pii>\n#define vb vector<bool>\n#define vvpi vector<vpi>\n#define MAXI 1000000007\n\nclass Solution {\npublic:\n\n struct cmp {\n bool operator() (pii a, pii b) {\n return a.first > b.first;\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "// Have to reduce time complexity\n\n/*\nT: O(E * (V+E)logV) \n\nMake graph without negative edges and find shortest distance from source to destination.\n\n Case 1: (shortest_dist < target)\n We can never make shortest_distance == target because we can not modify + edges.\n \n Case 2:... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n int k = 0;\n for (const auto& e: edges) {\n if (e[2] == -1) {\n ++k;\n }\n }\n\n if (dijkstr... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "using ll = long long;\n\nclass Solution {\npublic:\n\n static constexpr ll inf = 2e9 + 10;\n\n void dijkstra(int source, int destination, vector<vector<int>> &adj, vector<vector<int>> &edges, vector<ll> &d) {\n priority_queue<pair<ll, int>> pq;\n pq.emplace(0, source);\n fill(d.b... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "using ll = long long;\n\nclass Solution {\npublic:\n\n static constexpr ll inf = 2e9 + 10;\n\n void dijkstra(int source, int destination, vector<vector<int>> &adj, vector<vector<int>> &edges, vector<ll> &d, vector<int> &trace) {\n priority_queue<pair<ll, int>> pq;\n pq.emplace(0, source... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "typedef long long ll;\ntemplate<class T> using min_heap=priority_queue<T, vector<T>, greater<T>>;\nclass Solution {\npublic:\n ll dijkstra(int source, int destination, vector<vector<pair<int, ll>>> &g, int n) {\n vector<ll> dist(n, 1e17), vis(n, 0); min_heap<pair<ll, int>> q; q.push({0, source});... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n int dijkstra(int V, unordered_map<int,vector<pair<int,int>>> &adj, int S,int dest)\n {\n vector <int> dist(V,INT_MAX);\n vector <int> visit(V,0);\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n pq.push({0,S});\... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution\n{\npublic:\n int djkstra(int src, int dest, vector<pair<int, int>> adj[], int n)\n {\n vector<int> dist(n, 1e9);\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n pq.push({0, src});\n vector<int> vis(n, 0);\n whi... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution\n{\npublic:\n int djkstra(int src, int dest, vector<pair<int, int>> adj[], int n)\n {\n vector<int> dist(n, 1e9);\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n pq.push({0, src});\n vector<int> vis(n, 0);\n whi... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n vector<unordered_map<int, pair<int, bool>>> g(n);\n for (auto& e : edges) {\n int a = e[0], b = e[1], c = e[2];\n bool sp... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n // TC = log(E)*(E log(V)) \n\n #define F first\n #define S second\n #define pb push_back\n #define pii pair<int,int>\n #define vi vector<int>\n\n typedef long long int ll;\n const int INF = 2e9;\n\n vi parent, dist; // used in dijkstra\n vector<pii>... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n long long djk(int s, int d, int n, vector<vector<pair<int,int>>>&adj){\n vector<long long>dist(n,2e9);\n dist[s]=0;\n set<pair<long long,int>>st;\n st.insert({0,s});\n while(!st.empty()){\n auto f=st.begin();\n int x=f-... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n long long djk(int s, int d, int n, vector<vector<pair<int,int>>>&adj){\n vector<long long>dist(n,2e9);\n dist[s]=0;\n set<pair<long long,int>>st;\n st.insert({0,s});\n while(!st.empty()){\n auto f=st.begin();\n int x=f-... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n int MX = 2*1e9;\n int removed(int n, vector<vector<vector<int>>>& adj_list, vector<vector<int>>& edges, int src, int dest){\n\n vector<int>dist(n);\n\n for(int i=0;i<n;i++){\n dist[i] = INT_MAX;\n }\n\n priority_queue<vector<int>, vec... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n\tvector<vector<int>>modifiedGraphEdges(int n,vector<vector<int>>&edges,int source,int destination,int target){\n\t\tvector<vector<int>>variableEdges,ans,ans1;\n\t\tvector<pair<int,int>>adj1[n],adj2[n];\n\t\tfor(auto it:edges){\n\t\t\tif(it[2]==-1){\n\t\t\t\tvariableEdges.push_ba... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<int> al[128], w[128];\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n long long maxd = 2e9;\n for(int i=0; i<edges.size(); i++){\n al[edges[i][0]].push_back(edges[i][1]... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n int distance(vector<vector<int>> edges, int src, int des, int target,\n int n) {\n vector<int> dist(n, INT_MAX);\n vector<vector<pair<int, int>>> adj(n);\n for (auto it : edges) {\n if(it[2]!=-1){\n adj[it[0]].pus... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#define ll long long\n#define REP(i,n) FOR(i,0,n)\n#define SORT(v) sort((v).begin(),(v).end())\n#define FOR(i,a,b) for(ll i=(a);i<(b);i++)\n\nclass Solution {\npublic:\n ll djkstra(ll from, ll to, vector<vector<pair<ll, ll>>>& g) {\n ll n = g.size();\n priority_queue<pa... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n #define INF 0x3f3f3f3f\n vector<int> dij(int s, vector<vector<int> > g)\n {\n int n = g.size() - 1;\n vector<int> dis(g.size() + 2, INF);\n vector<int> vis(g.size() + 2, 0);\n dis[s] = 0;\n vis[s] = 0;\n for (int i = 0; i < n; i... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Node\n{\n public:\n int curr;\n int dist;\n int negativeWtEdgeIndex;\n Node(int c, int d, int i) : curr(c), dist(d), negativeWtEdgeIndex(i) {}\n};\nclass GreaterNode\n{\n public:\n bool operator() (const Node& p1, const Node& p2) const\n {\n return p1.dist > p2.dist;\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\n int dijk(int n, vector<unordered_map<int, int>> al, int source, int dest) {\n vector<int> dist(n, INT_MAX);\n set<pair<int,int>> s;\n\n dist[source] = 0;\n s.insert({dist[source], source});\n\n while (!s.empty()) {\n auto [d, node] = *s.be... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n using i64 = int64_t;\n const i64 inf = 2e9; \n\n /*\n If the shortest path after deleting all modified edges is smaller than `target`,\n then it is impossible, since this is an upper bound.\n \n If the shortest path after settings all modifie... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n g.resize(n);\n for(int i=0;i<edges.size();i++)\n {\n g[edges[i][0]].push_back({edges[i][1],edges[i][2],i});\n g[ed... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\nprivate:\n int source, dest;\n int n;\n vector<vector<int>> edges;\n int totalUnknowns = 0;\n void init(int _n, vector<vector<int>>& _edges, int _source, int _dest){\n n = _n;\n edges = _edges;\n source = _source;\n dest = _dest;\n totalUn... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<pair<int,int>>> adjc;\n vector<int> backtr, dists;\n int dijkstra(int n, int src, int dest) {\n dists.clear();\n dists.resize(n, -1);\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> relax;\n dists[... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#define vvi vector<vector<int>>\n\nclass cmp{\npublic:\n bool operator()(vector<int> p1, vector<int> p2){\n if(p1[0]<=p2[0]){\n return false;\n }\n else{\n return true;\n }\n }\n};\n\n\nclass Solution {\npublic:\n \n int bfs(int n, int src, int ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n int shortest_dist, last_editable_edge;\n static struct cmp {\n int operator()(pair<int, pair<int, int>>& a,\n pair<int, pair<int, int>>& b) {\n return a.second.first > b.second.first;\n }\n };\n int Dijkstra(vector<vecto... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "using ll = long long;\nusing T = tuple<int, ll, int, vector<int>>;\nclass Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n vector<unordered_map<int, ll>> adj(n);\n\n for (auto v : edges) {\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\nvector<int> findPath(vector<vector<int>> &mat, int curr, int d, vector<int> &ans , bool negEdge )\n{\n auto comp = [](vector<int> a, vector<int> b ){return a[0]>b[0];};\n priority_queue<vector<int>,vector<vector<int>>,decltype(comp)> q;\n q.push({0,curr});\n int n= mat.size();... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "/*\n 5\n ____________\n / -1 -1 \\\n(0)---(1)----(2)\n \\ |\n 2\\ |-1\n \\ |\n (3)\n\n 10\n _________\n 6 / 2 -1 \\\n(3)--(2)--(0)--(1)\n \\_________/\n -1\n\n -1\n _________\n -1 / 2 6 \\\n(3)--(2)--(0)--(1)\n \\_________/\n -1\n*/\... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#define ll long long\nclass Solution {\n int shortestDist(int n, vector<pair<int,int>> adj[n],int src,int dst){\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,1e9+7);\n dist[src]=0;\n\n while(... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "struct GValue {\n int d, v;\n \n GValue(int dist) {\n if (dist == -1) {\n d = 0;\n v = 1;\n } else {\n d = dist;\n v = 0;\n }\n }\n \n GValue() : GValue(INT32_MAX) {}\n \n bool operator==(const GValue& other) const {\n... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution \n{\nprivate:\n struct AdjInfo\n {\n int edgeId;\n int nodeId;\n int* weight;\n };\n\n struct Path\n {\n int dist;\n int from;\n int to;\n int edgeId;\n \n friend bool operator>(const Path& lhs, const Path& rhs)\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n int dijkstra(int n, vector<bool> & visited, unordered_map<int, unordered_map<int,int>> &adjList, vector<int> &distance, int source, int destination) {\n priority_queue<pair<int,int>, vector<pair<int,int>>, std::greater<pair<int,int>>> que;\n\n visited.assign(n, ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n vector<pair<int, int>> adj[n];\n vector<int> edgeId;\n for (int i = 0; i < edges.size(); ++i) {\n adj[edges[i][0]].push_back(... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "///////////////////////////////////////////////////\n\nusing grid_t = vector<vector<int>>;\nusing edge_t = vector<vector<int>>;\n\nusing ull = unsigned long long int;\nusing lint = long long int;\n\n// dijkstra and heap with priority updates\nnamespace my {\ntemplate <class Key, class Pri> class Heap {\npu... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n const int MAX = 2e9;\n vector<unordered_map<int, int>> adj;\n int shortestPath(int n, vector<vector<int>> &edges, int src, int dest) {\n vector<bool> vis(n, false);\n vector<int> dist(n, MAX);\n priority_queue<pair<int, int>, vector<pair<int, int>>,... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n \n // REMEMBER, THERE COULD BE MULTIPLE SHORTEST PATHS!!!!!!!\n // minimum path cost could be shared by:\n // 1. a fixed path\n // 2. as well as multiple adjustable paths!\n \n \n // have a few options of optimizing the code:\n // 1. tweak algo so that... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n struct Node {\n int vertex;\n int distance;\n\n bool operator>(const Node& other) const {\n return distance > other.distance;\n }\n };\n\n int dijkstra(int n, int source, int destination, vector<vector<pair<int, int>>>& graph) {\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n int find(vector<vector<pair<int,int>>>& v, int &source, int &destination, int &n){\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> q;\n q.push({0, source});\n vector<bool> done(n, false);\n while(!q.empty()){\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\n#define ll long long\n vector < ll> solve(int &n, vector<vector<vector<int>>> &adj, int &src) {\n vector<ll> dis(n, INT_MAX);\n dis[src] = 0;\n priority_queue<pair<ll, int>, vector<pair<ll, int>>,\n greater<pair<ll, int>>>\n pq;\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\n int shortestPath(int n, const vector<vector<pair<int, int>>>& neighbors, int source, int dest) {\n if (source == dest) return 0;\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;\n vector<int> visited(n, false);\n vector<i... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n const int INF=2*1e9;\n vector<vector<vector<int>>>g;\n vector<vector<int>>negatives;\n vector<int>dis;\n int n;\n bool f(int mid,int src,int dest,int target,vector<vector<int>>&edges){\n g.clear();\n g.resize(n);\n for(int i=0;i<mid;i++){\n... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution{\npublic:\n void bfs(int node, vector<vector<pair<int,int>>>&adj, vector<long long int>&dist){\n priority_queue<pair<long long int,long long int>, vector<pair<long long int,long long int>>, greater<pair<long long int,long long int>>>pq;\n pq.push({0,node});\n dist[nod... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution{\npublic:\n void bfs(int node, vector<vector<pair<int,int>>>&adj, vector<long long int>&dist){\n priority_queue<pair<long long int,long long int>, vector<pair<long long int,long long int>>, greater<pair<long long int,long long int>>>pq;\n pq.push({0,node});\n dist[nod... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n int64_t dijkstra(vector<vector<pair<int,int>>> const & adj, vector<int64_t> & minDist, \n vector<vector<int>> const & edges, int src, int dest) {\n const int N = adj.size();\n vector<bool> visit(N);\n using pr = pair<int64_t,int>; // c... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#define ll long long\n\nclass Solution {\npublic:\n ll dijkstra(vector<vector<pair<int, int>>>& g, int src, int dest, vector<ll> &dist) {\n priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> q;\n \n q.push({0L, src});\n while (!q.empty()) {\n auto [d, ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& e, int s, int d, int t) {\nint I=1e9+1;\nvector<unordered_map<int,int>> g(n);\nfor(auto &a:e)\n{\nif(a[2]==-1) continue;\ng[a[0]][a[1]]=g[a[1]][a[0]]=a[2];\n}\nfunction<int()> find=[&]()\n{\npriority_queue<pai... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "int w[100][100];\nclass Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n vector<vector<int>> adj(n);\n vector<int> minDist(n, 1000000000);\n for(vector<int> edge : edges){\n if(edg... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "const vector<vector<int>> init = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL), cout.tie(NULL);\n return vector<vector<int>>();\n}();\nclass Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "\nclass Solution {\nprivate:\n constexpr static const int maxW = 2000000000;\n\n using TPath = std::pair<int, int>;\n using TPathContainer = std::vector<TPath>;\n\n std::unordered_map<int, std::unordered_map<int, int>> edgs;\n\n int findMinW(const int n, const int source, const int destinati... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n\n const int INF = 2e9;\n\n void processDijkstrasNode(int node, int dist[], bool vis[], vector<vector<pair<int, int> > >& adjl, priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > >& pq) {\n vector<pair<int, int> > neighbours = adjl[node]... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\nprivate:\n int inf=2e9;\n\n int Dijkstra(int n,int st,int en,vector<vector<pair<int,int>>> adj){\n vector<int> dis(n,inf);\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n\n dis[st]=0;\n pq.push({0,st});\n\n while(... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n // build graph\n vector<vector<pair<int, int>>> graph(n);\n for(int i = 0; i < edges.size(); i++)\n {\n if(edges[i][2]... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<int> dijks(int source,vector<vector<pair<int,int>>>adj,int n){\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;\n vector<int> dist(n, INT_MAX);\n\n dist[source] = 0;\n pq.push({0,source});\n\n while(!... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std; \n\n#define ll long long\n#define pii pair<int, int>\n\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC optimize (\"unroll-loops\")\n\nclass Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& E, int st, int en, int targ) {... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std; \n\n#define ll long long\n#define pii pair<int, int>\n\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC optimize (\"unroll-loops\")\n\nclass Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& E, int st, int en, int targ) {... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n long long dij(int n, int src, int dest, vector<vector<int>>& edges) {\n // init \n vector<pair<int, long long>> adj[n];\n for(auto &edge: edges) {\n int x = edge.front();\n int y = edge[1];\n long long c = edge.back();\n\n... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n ll dij(int n, int src, int dest, vector<vector<int>>& edges) {\n // init \n vector<pair<int, ll>> adj[n];\n for(auto &edge: edges) {\n int x = edge.front();\n int y = edge[1];\n ll c = edge.back();\n\... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#pragma GCC optimize(\"O3\") // Optimize with level 3\n#pragma GCC target (\"avx2\")\n#pragma GCC optimization (\"unroll-loops\")\n\nclass Solution {\npublic:\n#define ll long long\n ll target;\n ll dijkstra(vector<vector<pair<int,ll>>> &adj , int src , int dest){\n int n = adj.size();\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<int> dijkstra(int& n, int& source, vector<vector<int>> adj[]) {\n vector<int> dist(n, 2e9);\n set<pair<int, int>> st;\n st.insert({0, source});\n dist[source] = 0;\n while(st.size()) {\n pair<int, int> top = *st.begin();\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n unordered_map<int, vector<pair<int, int>>> adj;\n \n for (auto& edge : edges) {\n int firstNode = edge[0], secondNode = edge[... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n auto Dijkstra = [&](int change) -> int {\n vector<pair<int, int>> adj[n];\n for (auto& edge : edges) {\n adj[edge... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "typedef pair<int,int> B;\nclass Solution {\npublic:\n const int INF = 2e9;\n\n vector<vector<int>> modifiedGraphEdges(int nodeCount,vector<vector<int>>& edges,\n int source, int destination,\n int target) {\n /... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "typedef pair<int,int> B;\nclass Solution {\npublic:\n const int INF = 2e9;\n\n vector<vector<int>> modifiedGraphEdges(int nodeCount,vector<vector<int>>& edges,\n int source, int destination,\n int target) {\n /... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\nprivate:\nconst int INF = 1e9+1;\nprivate:\nint getShortestPath(int n, int src, int dest,vector<vector<int>>&edges) {\n // create the graph\n vector<vector<pair<int,int>>> graph(n);\n for(auto &e: edges) {\n graph[e[0]].push_back({e[1],e[2]});\n graph[e[1]].push_bac... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\nprivate:\nconst int INF = 1e9+1;\nprivate:\nint getShortestPath(int n, int src, int dest,vector<vector<int>>&edges) {\n // create the graph\n vector<vector<pair<int,int>>> graph(n);\n for(auto &e: edges) {\n graph[e[0]].push_back({e[1],e[2]});\n graph[e[1]].push_bac... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "struct customLess {\npublic:\n bool operator() (pair<int, long long> a, pair<int, long long> b) {\n // vector has 2 ints --> (node, dist)\n return a.second < b.second;\n }\n};\n\nstruct pair_hash {\n template <class T1, class T2>\n std::size_t operator () (const std::pair<T1,T2> &... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution\n{\npublic:\n\n long long dijkstra(std::vector<std::vector<std::tuple<int, int *>>> &graph,\n int source,\n int destination)\n {\n auto n = graph.size();\n typedef long long Cost;\n typedef int Node;\n typedef std:... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<int> djik(int n,int s,int de,unordered_map<int,vector<vector<int>>>&mp,unordered_set<int>&st){\n vector<int>dist(n,2e9);\n dist[s]=0;\n queue<vector<int>>q;\n q.push({s,0});\n while(q.size()){\n auto it=q.front();\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n const int inf = 2e9;\n int dijkstra(int n,vector<vector<long long>> adj,int src,long long target,int dest)\n {\n vector<bool> vis(n,false);\n vector<long long> dist(n,inf);\n dist[src] = 0;\n for(int i=0;i<n;i++){\n int nextUnVisNo... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\n static constexpr auto kInvalid = std::numeric_limits<size_t>::max();\n\n int dijkstra(const std::vector<std::vector<std::pair<size_t, int>>>& adj_list, size_t source, size_t destination) {\n std::priority_queue<std::pair<int, size_t>, std::vector<std::pair<int, size_t>>, std... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\nprivate:\n long long dijkstra(int n, int source, int destination, vector<vector<int>>& adj) {\n priority_queue<pair<long long, int>> minHeap;\n vector<int> minDistances(n, -1);\n minHeap.push({0, source});\n minDistances[source] = 0;\n while (!minHeap... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "typedef pair<long long,int> pii;\n#define INF 2e9\nclass Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n vector<vector<pii>>edgelist(n);//{weight, node}\n for(auto &edge : edges){\n if(e... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "typedef pair<long long,int> pii;\n#define INF 2e9\nclass Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n vector<vector<pii>>edgelist(n);//{weight, node}\n for(auto &edge : edges){\n if(e... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n int dijkstra(vector<vector<int>>&edges,int n,int src,int dest){\n vector<pair<int,int>>adj[n];\n int e=edges.size();\n for(int i=0;i<e;i++){\n int u=edges[i][0],v=edges[i][1],wt=edges[i][2];\n if(wt!=-1){\n adj[u].push... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n typedef long long ll;\n typedef pair<int,int> P;\n\n int dijkstra(vector<vector<int>>& edges,int n,int src,int dst){\n \n priority_queue<P,vector<P>,greater<P>>pq;\n vector<pair<int,int>>adj[n];\n\n for(int i=0;i<edges.size();i++){\n i... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\n\npublic:\n typedef long long ll;\n typedef pair<int, int> P;\n ll DijikstraAlgo(int n, vector<vector<int>>& edges, int source,\n int destination) {\n vector< P> adj[n];\n for(auto &edge : edges){\n int u = edge[0];\n int v ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n typedef long long ll;\n typedef pair<int,int> P;\n\n int dijkstra(vector<vector<int>>& edges,int n,int src,int dst){\n \n priority_queue<P,vector<P>,greater<P>>pq;\n vector<pair<int,int>>adj[n];\n\n for(int i=0;i<edges.size();i++){\n i... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\nint dija(int n, vector<vector<int>>& edges, int src, int dest){\n vector<int>dis(n,INT_MAX);\n dis[src]=0;\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;q.push({0,src});\n vector<pair<int,int>>adj[n];\n for(auto &v:ed... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n typedef pair<long, long> P;\n const int LARGE_VALUE = 2e9;\n int shortest(int n, int s, int d,vector<vector<int>>&edge){\n vector<vector<pair<int, int>>> vec(n);\n for(int i=0; i<edge.size(); i++){\n int u=edge[i][0];\n int v=edge[i][1];\n int t=edge... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n long long dijkstra(const vector<vector<int>>& edges, int n, int src, int dest) {\n long long inf = numeric_limits<long long>::max();\n vector<vector<pair<int, int>>> adj(n);\n for (const auto& e : edges) {\n if (e[2] == -1) continue;\n ... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"Ofast\", \"inline\", \"unroll-loops\", \"no-stack-protector\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native\", \"f16c\")\n#define ll long long\n#define bigInt __int128_... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"Ofast\", \"inline\", \"unroll-loops\", \"no-stack-protector\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native\", \"f16c\")\n#define ll long long\n#define bigInt __int128_... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "typedef long long ll;\nint LARGE_VALUE = 2e9;\nclass Solution {\nprivate:\n ll Dijkstra(vector<vector<int>> &edges, int s, int d, int n) {\n unordered_map<int, vector<pair<int,int>>> adj;\n for(auto &i : edges) {\n if(i[2] != -1) {\n adj[i[0]].push_back({i[1], i[2... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "#define maxi 2*1e9 \nclass Solution {\npublic:\n int Dijkstra( int n,vector<vector<int>>& edges,int source,int destination){\n vector<pair<int,int>> adj[n];\n for(int i=0;i<(int)edges.size();i++){\n if(edges[i][2]==-1)continue;\n adj[edges[i][0]].push_back({edges[i][1... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n typedef int ll;\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n ll maxValue = 2 * 1e9;\n auto dijkstra = [&n,&edges,&source,&destination,&target]() -> ll {\n unordered_map< ll... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {\n int maxValue = 2 * 1e9;\n auto dijkstra = [&n,&edges,&source,&destination,&target]() -> int {\n unordered_map< int, vector< pair< in... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\nusing ll=long long;\nll dijkstra(int n,vector<vector<int>>&edges,int src,int dest){\n vector<pair<int,int>>g[n];\n for(auto &it:edges){\n if(it[2]!=-1){\n g[it[0]].push_back({it[1],it[2]});\n g[it[1]].push_back({it[0],it[2]});\n }\n }\... |
2,803 | <p>You are given an <strong>undirected weighted</strong> <strong>connected</strong> graph containing <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, and an integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge... | 3 | {
"code": "class Solution {\npublic:\nusing ll=long long;\nll dijkstra(int n,vector<vector<int>>&edges,int src,int dest){\n vector<pair<int,int>>g[n];\n for(auto &it:edges){\n if(it[2]!=-1){\n g[it[0]].push_back({it[1],it[2]});\n g[it[1]].push_back({it[0],it[2]});\n }\n }\... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.