id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 0 | {
"code": "using P2I = pair<int, int>;\nclass Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<P2I> g[n+1];\n for (auto& road : roads) {\n g[road[0]].push_back({road[1], road[2]});\n g[road[1]].push_back({road[0], road[2]});\n }\n\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 0 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<pair<int, int>> adj[100001];\n for (const vector<int>& road : roads) {\n const int cityA = road[0], cityB = road[1], dist = road[2];\n adj[cityA].push_back({cityB, dist});\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 0 | {
"code": "class Solution {\npublic:\n int fun(int node,vector<pair<int,int>> adj[],vector<int> &vis)\n {\n vis[node]=1;\n int ans=1e8;\n for(auto i:adj[node])\n {\n if(vis[i.first]==0)\n {\n ans=min({ans,i.second,fun(i.first,adj,vis)});\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 0 | {
"code": "\n\nclass Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<pair<int, int>> adj[n + 1];\n \n // Construct adjacency list\n for (const auto& road : roads) {\n int u = road[0], v = road[1], w = road[2];\n adj[u].push_back({v,... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<vector<pair<int,int>>>adjlst(n+1);\n vector<bool>vis(n+1,false);\n\n for(auto & road: roads){\n int u=road[0];\n int v=road[1];\n int dis=road[2];\n adj... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<pair<int,int>>adj[n+1];\n for(int i=0;i<roads.size();i++){\n adj[roads[i][0]].push_back({roads[i][1],roads[i][2]});\n adj[roads[i][1]].push_back({roads[i][0],roads[i][2]});\n\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "\nclass DisjointSet\n{\n vector<int> size,parent;\n public:\n DisjointSet(int n)\n {\n parent.resize(n+1);\n size.resize(n+1,1);\n for (int i=1;i<=n;i++)\n parent[i]=i;\n }\n int find(int x)\n {\n if (x==parent[x])\n return x;\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "class Solution {\npublic:\n void dfs(int u, vector<vector<pair<int,int>>> &adj, vector<bool> &vis, int dist, int& ans, int n){ \n // traverse all edges that can be reachable from 1\n for(auto ne : adj[u]){\n int v = ne.first;\n int d = ne.second;\n i... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<vector<pair<int, int>>> graph(n + 1);\n for (vector<int>& edge : roads) {\n int from = edge[0];\n int to = edge[1];\n int dist = edge[2];\n graph[from].push_ba... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "class Solution {\npublic:\n vector<int> list;\n vector<bool> vis;\n void dfs(int v, vector<vector<pair<int, int>>>& adj){\n vis[v] = true;\n list.push_back(v);\n for(pair<int, int> u: adj[v]){\n if(!vis[u.first]){\n dfs(u.first, adj);\n }\n... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<vector<pair<int, int>>> graph(n+1);\n\n for (auto& it : roads) {\n int u = it[0];\n int v = it[1];\n int dist = it[2];\n\n graph[u].emplace_back(v, dist);\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n\n vector<vector<pair<int,int>>>graph(n+1);\n for(vector<int>&road : roads){\n graph[road[0]].push_back({road[1], road[2]});\n graph[road[1]].push_back({road[0], road[2]});\n }\n\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<vector<pair<int,int>>>adj(n+1);\n for(int i=0;i<roads.size();i++){\n adj[roads[i][0]].push_back({roads[i][1],roads[i][2]});\n adj[roads[i][1]].push_back({roads[i][0],roads[i][2]}); \n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int,vector<pair<int,int>>> mp(n);\n for(int i=0;i<roads.size();i++){\n mp[roads[i][0]-1].push_back({roads[i][1]-1,roads[i][2]});\n mp[roads[i][1]-1].push_back({roads[i][0]-1,... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<pair<int,int>> adj[n+1];\n for(auto it: roads)\n {\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n }\n int mn=1e9;\n bool... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int,vector<pair<int,int>>>adj;\n \n for(vector<int>&vec : roads){\n int a = vec[0];\n int b = vec[1];\n int dis = vec[2];\n\n adj[a].push_back({b... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 1 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<pair<int, int>> adjList[n + 1];\n vector<int> visited(n + 1, 0);\n for(auto i : roads){\n adjList[i[0]].push_back({i[1], i[2]});\n adjList[i[1]].push_back({i[0], i[2]});\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n \n vector<pair<int,int>>adj[n];\n for(auto it:roads){\n adj[it[0]-1].push_back({it[1]-1,it[2]});\n adj[it[1]-1].push_back({it[0]-1,it[2]});\n }\n vector<int>visited(n,... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\nprivate:\n void dfs(int node,int &ans, unordered_map<int, vector<pair<int,int>> > &adj, vector<bool> &vis){\n if(vis[node]) return;\n vis[node] = true;\n\n for(const auto& ngb: adj[node]){\n ans = min(ans, ngb.second);\n dfs(ngb.first,ans, adj... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\nint ans;\n\nvoid dfs(int node,map<int,vector<pair<int,int>>>&adj,vector<int>&vis){\n\n \n for(auto it:adj[node]){\n int adjNode=it.first;\n int wt=it.second;\n ans=min(ans,wt);\n if(!vis[adjNode]){\n vis[adjNode]=1;\n dfs(ad... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n\n void dfs(int u, unordered_map<int, vector<pair<int, int>>> &adj, int &result, vector<int> &visited ){\n \n visited[u] = true;\n for(auto &temp: adj[u]){\n int v = temp.first;\n int dist = temp.second;\n result = min(r... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\nint ans;\n\nvoid dfs(int node,map<int,vector<pair<int,int>>>&adj,vector<int>&vis){\n\n \n for(auto it:adj[node]){\n int adjNode=it.first;\n int wt=it.second;\n ans=min(ans,wt);\n if(!vis[adjNode]){\n vis[adjNode]=1;\n dfs(ad... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n\n void dfs(int node, map<int, vector<pair<int,int>>>& adjList, int& minVal, vector<int>& vis) {\n \n vis[node] = 1;\n for(auto it: adjList[node]) {\n int adjNode = it.first;\n int score = it.second;\n\n minVal = min(minVal... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<pair<int,int>> adj[n+1];\n int max_dist=INT_MIN;\n for(auto it:roads){\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n max_dist=max... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<pair<int,int>>adj[n+1];\n\n for(auto it:roads){\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n }\n\n vector<int>dis(n+1,1e9);\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<pair<int,int>> adjList[n+1];\n\n for(auto it : roads){\n int u = it[0];\n int v = it[1];\n int wt = it[2];\n adjList[u].push_back({v,wt});\n adjList... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n void dfs(int node, int &mini, vector<vector<pair<int, int>>>& adj, vector<bool>& vis) {\n if (vis[node]) return;\n vis[node] = true;\n for (auto it : adj[node]) {\n mini = min(mini, it.second);\n dfs(it.first, mini, adj, vis);\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n\n int mini = INT_MAX;\n vector<vector<pair<int,int>>> adj;\n\n void dfs(int p, vector<int>&vis) {\n vis[p] = 1;\n for(int i=0;i<adj[p].size();i++) {\n mini = min(mini, adj[p][i].second);\n if(!vis[adj[p][i].first]) {\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n\n int mini = INT_MAX;\n vector<vector<pair<int,int>>> adj;\n\n void dfs(int p, vector<int>&vis) {\n for(int i=0;i<adj[p].size();i++) {\n mini = min(mini, adj[p][i].second);\n if(!vis[adj[p][i].first]) {\n vis[adj[p][i].first] ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n vector<int>Size,parent;\n int find(int node){\n if(parent[node]==node)return node;\n return parent[node]=find(parent[node]);\n }\n void group(int u,int v){\n u=find(u);\n v=find(v);\n if(Size[v]>Size[u])swap(u,v);\n parent[v]... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n vector<int>Size,parent;\n int find(int node){\n if(parent[node]==node)return node;\n return parent[node]=find(parent[node]);\n }\n void group(int u,int v){\n u=find(u);\n v=find(v);\n if(Size[v]>Size[u])swap(u,v);\n parent[v]... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n \n unordered_map<int, vector<pair<int, int> > > adj;\n for(int i=0; i<roads.size(); i++)\n {\n int u = roads[i][0];\n int v = roads[i][1];\n int w = roads[i][2];\n... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 2 | {
"code": "class Solution {\npublic:\n int bfs( unordered_map<int, vector<pair<int,int>>>& mp, int start,unordered_set<int>& visited)\n {\n int res = INT_MAX;\n queue<int>q;\n q.push(start);\n visited.insert(start);\n \n while(!q.empty())\n {\n int nod... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<int> dis(n+1,1e8);\n vector<vector<pair<int,int>>> adj(n+1);\n for(auto it:roads){\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n }\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<vector<pair<int, int>>> adj(n+1);\n for (auto itr : roads) {\n adj[itr[0]].push_back({itr[2], itr[1]});\n adj[itr[1]].push_back({itr[2], itr[0]});\n }\n\n priority_que... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n void dfs(unordered_map<int,vector<pair<int,int>>>& mp, set<int>& visited, int& ans, int ele)\n {\n if(visited.find(ele) != visited.end())\n return;\n \n visited.insert(ele);\n for(auto ele2:mp[ele])\n {\n ans = min(a... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int,vector<pair<int,int>>> graph;\n for(int i=0;i<roads.size();i++){\n graph[roads[i][0]].push_back({roads[i][1],roads[i][2]});\n graph[roads[i][1]].push_back({roads[i][0],ro... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int, vector<pair<int,int>>> adj;\n for(int i=0;i<roads.size();i++){\n adj[roads[i][0]].push_back({roads[i][1],roads[i][2]});\n adj[roads[i][1]].push_back({roads[i][0],roads[i... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> g;\n vector<bool> vis;\n int ans=INT_MAX;\n void dfs(int node){\n // cout<<\"node \"<<node<<endl;\n vis[node]=true;\n for(int i=0;i<g[node].size()-1;i+=2){\n ans=min(ans,g[node][i+1]);\n if(!vis[g[node][i... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int,vector<pair<int,int>>>adj; \n int ans=INT_MAX; \n for(auto i:roads) \n {\n adj[i[0]].push_back({i[1],i[2]});\n adj[i[1]].push_back({i[0],i[2]});\n }\... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int,vector<pair<int,int>>>adj;\n for(int i=0;i<roads.size();i++){\n adj[roads[i][0]].push_back({roads[i][1],roads[i][2]});\n adj[roads[i][1]].push_back({roads[i][0],roads[i][... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int ans = INT_MAX;\n void dfs(int node , unordered_map<int,vector<pair<int,int>>> & adj , vector<int> & visit){\n visit[node] = true;\n for(auto i : adj[node]){\n ans = min(ans,i.second);\n if(!visit[i.first]){\n dfs(i.fir... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n map<int,vector<pair<int,int>>> g;\n for(auto i : roads) {\n g[i[0]].push_back({i[1], i[2]});\n g[i[1]].push_back({i[0], i[2]});\n }\n vector<int> vis(n + 1);\n queue<i... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n void dfs(unordered_set<int>& visited, unordered_map<int, vector<int>>& adjacency_list, int n) {\n if (visited.find(n) != visited.end())\n return;\n\n visited.insert(n);\n for (int neighbor : adjacency_list[n])\n dfs(visited, adjacenc... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic : \nvoid dfs(unordered_map<int, list<pair<int, int>>>& adj, vector<bool>& visited, int start, int &ans)\n {\n visited[start] = true ;\n // cout<<start<<\" \"<<ans<<endl ;\n for(auto it : adj[start])\n {\n // cout<<it.first<<endl ;\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n void solve(int node, int &ans, unordered_map<int, vector<pair<int, int>>> &v, vector<int> &visit) {\n if(visit[node] >= 2) return;\n\n visit[node]++;\n for(auto x : v[node]) {\n ans = min(ans, x.second);\n solve(x.first, ans, v, visi... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n \n unordered_map<int, vector<pair<int, int>>> adj;\n for(auto road : roads) {\n adj[road[0]].push_back({road[1], road[2]});\n adj[road[1]].push_back({road[0], road[2]});\n }\... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class DSU{\n public:\n #define vi vector<int>\n vi sz,pr;\n DSU(int n){\n sz.resize(n+1,1);\n pr.resize(n+1);\n for(int i=0;i<=n;i++)pr[i]=i;\n }\n int fp(int u){\n if(pr[u]==u)return u;\n return pr[u]=fp(pr[u]);\n }\n void ubs(int u,int v){\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n map<int,vector<pair<int,int>>>mp;\n for(auto i:roads){\n mp[i[0]].push_back({i[1],i[2]});\n mp[i[1]].push_back({i[0],i[2]});\n }\n int total_mini=INT_MAX;\n queue<pair... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n map<int,vector<pair<int,int>>>mp;\n for(auto i:roads){\n mp[i[0]].push_back({i[1],i[2]});\n mp[i[1]].push_back({i[0],i[2]});\n }\n int total_mini=INT_MAX;\n queue<pair... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n void bfs(unordered_map<int,vector<int>> & adj , vector<int> & visit){\n queue<int> q;\n q.push(1);visit[1] = true;\n\n while(!q.empty()){\n int node = q.front();q.pop();\n for(auto i : adj[node]){\n if(!visit[i]){\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n void solve(int node, int &ans, map<int, vector<pair<int, int>>> &v, vector<int> &visit) {\n if(visit[node] > 2) return;\n\n visit[node]++;\n for(auto x : v[node]) {\n ans = min(ans, x.second);\n solve(x.first, ans, v, visit);\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<int> dis(n+1,1e8);\n vector<vector<pair<int,int>>> adj(n+1);\n for(auto it:roads){\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n }\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<vector<pair<int,int>>> adj(n+1);\n for(auto it:roads)\n {\n int u=it[0];\n int v=it[1];\n int dist=it[2];\n adj[u].push_back({v,dist});\n adj... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<int,vector<pair<int,int>>> tree;\n unordered_set<int> vi;\n int val = INT_MAX;\n\n void dfs(int node, int n){\n if (vi.find(node)!=vi.end()) return;\n vi.insert(node);\n for (auto x : tree[node]){\n val = min(val,x.second... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int i, vector<vector<int>>& roads, unordered_map<int, vector<pair<int,int>>>& adj, unordered_set<int>& visited, int& res){\n if(visited.count(i)!=0){\n return;\n }\n visited.insert(i);\n for(auto e:adj[i]){\n res=min(... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int,list<pair<int,int>>>adj;\n for(int i=0;i<roads.size();i++)\n {\n int u=roads[i][0];\n int v=roads[i][1];\n int w=roads[i][2];\n adj[u].push_b... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n //min-heap (if we can reach the certain dest with some mini && and if we can reach\n // the same dest <that push then we can end up with the least)\n vector<int>dist(n+1,INT_MAX);\n vector<pair<in... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<vector<pair<int,int>>> adj(n+1);\n \n for(auto i:roads){\n int u=i[0];\n int v=i[1];\n int d=i[2];\n \n adj[u].push_back({v,d});\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int,list<pair<int,int>>> adj;\n for(int i=0;i<roads.size();i++){\n int u=roads[i][0];\n int v=roads[i][1];\n int w=roads[i][2];\n adj[u].push_back({v,w}... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<pair<int,int>>> g;\n bool vis[100001];\n set<pair<int,int>> s;\n\n // static bool cmp(vector<int>& a, vector<int>& b) {\n // return a[0] < b[0];\n // }\n\n void dfs(int node, int parent = -1) {\n vis[node] = true;\n for(auto n... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n map <int,vector<pair<int,int>>> adj;\n\n for(auto it : roads) {\n int u = it[0] , v = it[1] , c = it[2];\n adj[u].push_back({v,c});\n adj[v].push_back({u,c});\n }\n\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n //cost will the min cost of comp in which node 1 belong to\n map <int,vector<pair<int,int>>> adj;\n\n for(auto it : roads) {\n int u = it[0] , v = it[1] , c = it[2];\n adj[u].push_b... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int bfs(unordered_map<int, list<pair<int,int>>>& mp, int start, vector<int>& visited) {\n queue<int> q;\n q.push(start);\n visited[start] = 1;\n\n int ans = INT_MAX;\n while (!q.empty()) {\n int node = q.front();\n q.po... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n void dfsVisit(vector<vector<int>> adj[], int& ans, int node,\n vector<bool>& visited) {\n visited[node] = true;\n for (auto& a : adj[node]) {\n ans = min(ans, a[1]);\n if (!visited[a[0]]) {\n dfsVisit(adj, an... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& adj,map<pair<int,int>,int>& mp,int& res,vector<int>& visited,int src)\n {\n visited[src]=1;\n\n for(int i=0;i<adj[src].size();i++)\n {\n if(!visited[adj[src][i]])\n {\n res=min(res,mp[m... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<vector<int>> adj[n+1];\n for(int i=0;i<roads.size();i++)\n {\n adj[roads[i][0]].push_back({roads[i][1],roads[i][2]});\n adj[roads[i][1]].push_back({roads[i][0],roads[i][2]});... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<int,list<pair<int,int>>>adjList;\n void dfs(int src,unordered_map<int,bool>&visited,int &result){\n visited[src]=true;\n for(auto nbr:adjList[src]){\n int n=nbr.first,d=nbr.second;\n result=min(result,d);\n if(!v... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Disjointset{\n public:\n vector<int> parent;\n vector<int> rank;\n Disjointset(int n){\n parent.resize(n);\n rank.resize(n,0);\n for(int i=0;i<n;i++){\n parent[i] = i;\n\n }\n }\n\n int findparent(int node){\n if(parent[node] == node) re... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& edges) {\n unordered_map<int, int> g[n];\n for (vector<int>& edge : edges) {\n int a = edge[0] - 1;\n int b = edge[1] - 1;\n int c = edge[2];\n g[a][b] = c;\n g[b][a]... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class disjointset{\n public :\n map<int,int>rankmap;\n map<int,int>parentmap;\n void createset(int x){\n parentmap[x] = x;\n rankmap[x] = 1;\n }\n int findset(int x){\n if(parentmap[x] == x){\n return x;\n }\n return parentmap[x] = findset(par... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class disjointset{\n public :\n map<int,int>rankmap;\n map<int,int>parentmap;\n void createset(int x){\n parentmap[x] = x;\n rankmap[x] = 1;\n }\n int findset(int x){\n if(parentmap[x] == x){\n return x;\n }\n return parentmap[x] = findset(par... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<vector<int>> adj[n+1];\n\n for (auto &vec: roads) {\n adj[vec[0]].push_back({vec[1], vec[2]});\n adj[vec[1]].push_back({vec[0], vec[2]});\n } \n\n priority_queue<pa... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n #define pp pair<int , int>\n \n int minScore(int n, vector<vector<int>>& v) {\n \n vector<vector<int>> adj[n];\n \n for(auto& x : v)\n {\n adj[x[0] - 1].push_back({x[1] - 1 , x[2]});\n adj[x[1] - 1].push_back({x[0... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n void solve(int s,int &ans,vector<vector<vector<int>>> &g,vector<bool> &v){\n if(v[s])return;\n v[s] = true;\n for(auto &i: g[s]){\n ans = min(ans,i[1]);\n solve(i[0],ans,g,v);\n }\n }\n int minScore(int n, vector<vector<... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n void solve(int s,int &ans,vector<vector<vector<int>>> &g,vector<bool> &v){\n if(v[s])return;\n v[s] = true;\n for(auto &i: g[s]){\n ans = min(ans,i[1]);\n solve(i[0],ans,g,v);\n }\n }\n int minScore(int n, vector<vector<... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<vector<vector<int>>> g(n+1);\n for(auto &i: roads){\n g[i[0]].push_back({i[1],i[2]});\n g[i[1]].push_back({i[0],i[2]});\n }\n int ans = INT_MAX;\n vector<bool> ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n void solve(int s,int &ans,vector<vector<vector<int>>> &g,vector<bool> &v){\n if(v[s])return;\n v[s] = true;\n for(auto &i: g[s]){\n ans = min(ans,i[1]);\n solve(i[0],ans,g,v);\n }\n }\n int minScore(int n, vector<vector<... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n vector<vector<vector<int>>> adj(n+1);\n\n for (int i = 0; i < roads.size(); i++)\n {\n adj[roads[i][0]].push_back({roads[i][1], roads[i][2]});\n adj[roads[i][1]].push_back({roads[i]... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int,list<pair<int,int>>> adj;\n for(auto i : roads)\n {\n adj[i[0]].push_back({i[1],i[2]});\n adj[i[1]].push_back({i[0],i[2]});\n }\n\n vector<int> dis... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int,list<pair<int,int>>> adj;\n for(auto i : roads)\n {\n adj[i[0]].push_back({i[1],i[2]});\n adj[i[1]].push_back({i[0],i[2]});\n }\n\n vector<int> dis... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int, vector<vector<int>>> al;\n for (const auto& road : roads) {\n al[road[0]-1].push_back({road[1]-1, road[2]});\n al[road[1]-1].push_back({road[0]-1, road[2]});\n }\... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\nvoid dfs(int node, int& ans, vector<vector<int>>& g, vector<bool>& vis, map<pair<int, int>, int>& cost) {\n\n\n\tvis[node] = true;\n\n\tfor (auto neigh : g[node]) {\n\n\t\tif (!vis[neigh] || cost[{neigh, node}] < ans) {\n\t\t\tans = min(ans, cost[{neigh, node}]);\n\t\t\tdfs(neigh... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "\nclass Solution\n{\npublic:\n int my_n;\n int minDist;\n vector<unordered_map<int, int>> nodesConnect; // i node와 연결된 다른 node 목록\n vector<bool> visit;\n bool DFS(int v)\n {\n int res = false;\n if (v == 1 || v == my_n)\n res = true;\n\n visit[v] = true;\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "#define N 100001\nclass Solution {\npublic:\n vector<int> id, sz, score;\n Solution(){\n id.resize(N);\n sz.resize(N, 1);\n score.resize(N, INT_MAX);\n }\n int find(int p){\n int root = p;\n while(id[root] != root){\n root = id[root];\n }\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution\n{\npublic:\n int my_n;\n int minDist;\n vector<unordered_map<int, int>> nodesConnect; // i node와 연결된 다른 node 목록\n vector<bool> visit;\n bool DFS(int v)\n {\n int res = false;\n if (v == 1 || v == my_n)\n res = true;\n\n visit[v] = true;\n ... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\n private:\n void dfs(int node, unordered_map<int, vector<vector<int>>> &adjMat, vector<int> &reachable) {\n reachable[node] = 1;\n for (vector<int> &i : adjMat[node]) {\n if (!reachable[i[0]]) {\n reachable[i[0]] = 1;\n dfs(i[0],... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int, unordered_map<int, int>> edge_map;\n for (int i = 0; i < roads.size(); i++) {\n if (edge_map.find(roads[i][0]) == edge_map.end() ||\n edge_map[roads[i][0]].find(road... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& roads) {\n unordered_map<int, unordered_map<int, int>> edge_map;\n for (int i = 0; i < roads.size(); i++) {\n if (edge_map.find(roads[i][0]) == edge_map.end() ||\n edge_map[roads[i][0]].find(road... |
2,582 | <p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>, distance<sub>i</sub>]</code> indicates that there is a <strong>bid... | 3 | {
"code": "class Solution {\npublic:\n int minScore(int n, vector<vector<int>>& road) {\n \n int N=road.size();\n vector<vector<pair<int,int>>>ans(n+1);\n for(int i=0;i<N;i++)\n {\n \n \n \n \n \n \n ... |
2,720 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>p</code>. Find <code>p</code> pairs of indices of <code>nums</code> such that the <strong>maximum</strong> difference amongst all the pairs is <strong>minimized</strong>. Also, ensure no index appears more than once among... | 0 | {
"code": "class Solution {\npublic:\n Solution(){\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n }\n int check(int mid,vector<int>& nums){\n int n=nums.size();\n int cnt=0;\n for(int i=0;i<n-1;i++){\n if(nums[i+1]-nums[i] <= mid){\n ... |
2,720 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>p</code>. Find <code>p</code> pairs of indices of <code>nums</code> such that the <strong>maximum</strong> difference amongst all the pairs is <strong>minimized</strong>. Also, ensure no index appears more than once among... | 0 | {
"code": "class Solution {\npublic:\n Solution() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr); \n cout.tie(nullptr);\n }\n // Find the number of valid pairs by greedy approach\n int countValidPairs(vector<int>& nums, int threshold) {\n int index = 0, count = 0, n = nums... |
2,720 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>p</code>. Find <code>p</code> pairs of indices of <code>nums</code> such that the <strong>maximum</strong> difference amongst all the pairs is <strong>minimized</strong>. Also, ensure no index appears more than once among... | 0 | {
"code": "class Solution {\npublic:\n Solution() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr); \n cout.tie(nullptr);\n }\n // Find the number of valid pairs by greedy approach\n int countValidPairs(vector<int>& nums, int threshold) {\n int index = 1, count = 0, n = nums... |
2,720 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>p</code>. Find <code>p</code> pairs of indices of <code>nums</code> such that the <strong>maximum</strong> difference amongst all the pairs is <strong>minimized</strong>. Also, ensure no index appears more than once among... | 0 | {
"code": "class Solution {\npublic:\n int minimizeMax(vector<int>& nums, int p) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr); \n cout.tie(nullptr);\n if (p == 0) {\n return 0;\n }\n\n sort(nums.begin(), nums.end());\n\n int l = 0, r = nums... |
2,720 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>p</code>. Find <code>p</code> pairs of indices of <code>nums</code> such that the <strong>maximum</strong> difference amongst all the pairs is <strong>minimized</strong>. Also, ensure no index appears more than once among... | 0 | {
"code": "class Solution {\npublic:\n Solution(){\n ios_base :: sync_with_stdio(false);\n }\n bool isPossible(vector<int>& nums, int p,int maxDiff){\n int n = nums.size();\n int pairs = 0;\n for(int i = 1;i<n;i++){\n if(abs(nums[i]-nums[i-1]) <= maxDiff){\n ... |
2,720 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>p</code>. Find <code>p</code> pairs of indices of <code>nums</code> such that the <strong>maximum</strong> difference amongst all the pairs is <strong>minimized</strong>. Also, ensure no index appears more than once among... | 0 | {
"code": "class Solution {\n bool check(vector<int>& nums, int diff, int p){\n int ans = 0;\n for(int i = 0; i < nums.size() - 1; i++){\n if(nums[i + 1] - nums[i] <= diff)\n {\n p--; i++;\n }\n if(p == 0) return true;\n }\n ret... |
2,720 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>p</code>. Find <code>p</code> pairs of indices of <code>nums</code> such that the <strong>maximum</strong> difference amongst all the pairs is <strong>minimized</strong>. Also, ensure no index appears more than once among... | 0 | {
"code": "// Time: O(NlogN)\n// Space: O(1)\nclass Solution {\npublic:\n int minimizeMax(vector<int>& A, int P) {\n sort(begin(A), end(A));\n int N = A.size(), L = 0, R = A.back() - A[0];\n auto valid = [&](int t) {\n int cnt = 0;\n for (int i = 1; i < N && cnt < P;) {\n... |
2,720 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>p</code>. Find <code>p</code> pairs of indices of <code>nums</code> such that the <strong>maximum</strong> difference amongst all the pairs is <strong>minimized</strong>. Also, ensure no index appears more than once among... | 0 | {
"code": "class Solution {\npublic:\n/* Find the min value for pair difference so that the pairs whose difference ls less than the value\nis less than p.\n*/\n int minimizeMax(vector<int>& nums, int p) {\n sort(nums.begin(), nums.end()); \n int l = 0;\n int r = nums.back() - nums.front();\n w... |
2,720 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>p</code>. Find <code>p</code> pairs of indices of <code>nums</code> such that the <strong>maximum</strong> difference amongst all the pairs is <strong>minimized</strong>. Also, ensure no index appears more than once among... | 0 | {
"code": "class Solution {\n bool doesPpairExist(vector<int>& nums, int mid, int p) {\n int count = 0;\n int i = 0;\n while (i < nums.size() - 1) {\n if (nums[i + 1] - nums[i] <= mid) {\n i += 2;\n count++;\n } else {\n ++i;\n... |
2,720 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>p</code>. Find <code>p</code> pairs of indices of <code>nums</code> such that the <strong>maximum</strong> difference amongst all the pairs is <strong>minimized</strong>. Also, ensure no index appears more than once among... | 1 | {
"code": "class Solution {\npublic:\n bool valid(vector<int>& nums, int p,int mid){\n bool taken=false;\n int cnt=0;\n for(int i=1;i<nums.size();i++){\n if(taken){\n taken=false;\n }\n else if(nums[i]-nums[i-1]<=mid){\n cnt++, tak... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.