id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nuint8_t disableSync = []() noexcept\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n long long maximumImportance(const int order, const std::... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "class Solution {\npublic:\n static long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> deg(n, 0);// deg(v)=# of of paths containng v \n for(auto& e: roads){\n deg[e[0]]++;\n deg[e[1]]++;\n }\n sort(deg.begin(), deg.end());\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "class Solution {\npublic:\n static long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> deg(n, 0);// deg(v)=# of of paths containng v \n for(auto& e: roads){\n deg[e[0]]++;\n deg[e[1]]++;\n }\n sort(deg.begin(), deg.end());\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "class Solution {\npublic: //Joy is destructive ... Peace doesn't need it\n static long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> deg(n, 0); //You can't have debt to an animal if you want to make it to mars ... synthetic or IP\n for(auto& e: roads){\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "using ll = long long;\nclass Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> deg(n);\n for (const auto &e : roads) {\n int a = e[0];\n int b = e[1];\n deg[a]++;\n deg[b]++;\n }\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector < int > a(n, 0);\n for (const auto& x: roads) {\n for (const auto xv: x) {\n a[xv]++;\n }\n }\n sort(a.begin(), a.end());\n long l... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> d (n, 0);\n for(vector<int>& e: roads) {\n d[e[0]]++;\n d[e[1]]++;\n }\n sort(d.begin(), d.end());\n long long ret = 0;\n for(int i =... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int>v(n, 0);\n for(int i = 0;i<roads.size();i++){\n v[roads[i][0]]++;\n v[roads[i][1]]++;\n }\n sort(v.begin(), v.end());\n long long res = 0;\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "//Approach (using degree and assiging value greedily)\n//T.C : O(E + nlogn)\nclass Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n //n = total number of nodes numbered from 0 to n-1\n\n vector<int> degree(n, 0);\n\n for(auto &vec : roads) {\n... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n vector<long long> deg(n,0);\n for(auto &road : roads) {\n int a = road[0], b = road[1];\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n vector<long long> deg(n,0);\n for(auto &road : roads) {\n int a = road[0], b = road[1];\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n ios::sync_with_stdio(false) ;\n cin.tie(nullptr) ;\n\n vector<long long> deg(n, 0) ;\n for(auto &r : roads){\n deg[r[0]]++ ; deg[r[1]]++ ;\n }\n \n s... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<long long> degree(n,0);\n\n for(int i=0;i<roads.size();i++){\n degree[roads[i][0]]++;\n degree[roads[i][1]]++;\n }\n sort(degree.begin(),degree.end());\... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<long long> roadDegree(n, 0);\n for (int i = 0; i < roads.size(); i++){\n roadDegree[roads[i][0]]++;\n roadDegree[roads[i][1]]++;\n }\n sort (roadDegree.... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 0 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<long long> degrees(n, 0);\n for(int i = 0; i < roads.size(); i++){\n degrees[roads[i][0]]++;\n degrees[roads[i][1]]++;\n }\n sort(degrees.begin(), degre... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\ntypedef long long ll;\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> mp(n,0);\n for(auto &road : roads){\n mp[road[0]]++;\n mp[road[1]]++;\n }\n vector<int> v(n,0);\n iota(begin(v), end(... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\ntypedef long long ll;\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> mp(n,0);\n for(auto &road : roads){\n mp[road[0]]++;\n mp[road[1]]++;\n }\n vector<int> v(n,0);\n iota(begin(v), end(... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> degree(n, 0);\n for (const auto& road : roads) {\n degree[road[0]]++;\n degree[road[1]]++;\n }\n \n vector<int> cities(n);\n for (int... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> times;\n for (int i = 0; i < n; i++) {\n times.push_back(0);\n }\n int city;\n for (vector<vector<int>>::iterator h = roads.begin(); h != roads.end(); ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> times;\n for (int i = 0; i < n; i++) {\n times.push_back(0);\n }\n int city;\n for (vector<vector<int>>::iterator h = roads.begin(); h != roads.end(); ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n // So assign each city a value from 1 to n\n // \"Value\" of each road will be sum of two adjacent cities it connects\n // We can just find the cities which touch most roads?\n // A... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n unordered_map<int,vector<int>>adjList;\n vector<long long>indegree(n,0);\n vector<int>val(n,0);\n for(auto & road:roads){\n int u=road[0];\n int v=road[1];\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> city_importance(n, 0);\n \n vector<long long> count(n, 0); // freq, node_id\n\n for (const auto& road : roads) {\n count[road[0]] += 1;\n count[roa... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> city_importance(n, 0);\n \n vector<long long> count(n, 0); // freq, node_id\n\n for (const auto& road : roads) {\n count[road[0]] += 1;\n count[roa... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> rank(n);\n for (vector<int>& road : roads) {\n rank[road[0]]++;\n rank[road[1]]++;\n }\n\n priority_queue<long long> max_heap(rank.begin(), rank.en... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> deg(n,0);\n for(auto &road : roads) {\n int a = road[0], b = road[1];\n ++deg[a], ++deg[b];\n }\n\n priority_queue<int> pq;\n for(int i = 0;... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> deg(n,0);\n for(auto &road : roads) {\n int a = road[0], b = road[1];\n ++deg[a], ++deg[b];\n }\n\n priority_queue<int> pq;\n for(int i = 0;... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, const vector<vector<int>>& roads) {\n vector<int> degree(n, 0);\n for (const auto& r: roads) {\n degree[r[0]]++;\n degree[r[1]]++;\n }\n sort(degree.rbegin(), degree.rend());\n long lo... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> indegree;\n map<int, vector<int>> valueMap;\n indegree.resize(n);\n\n for(int i = 0; i < roads.size(); i++) {\n indegree[roads[i][0]]++;\n indegree... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, const vector<vector<int>>& roads) {\n vector<int> degree(n, 0);\n for (const auto& r: roads) {\n degree[r[0]]++;\n degree[r[1]]++;\n }\n sort(degree.rbegin(), degree.rend());\n long lo... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, const vector<vector<int>>& roads) {\n vector<int> degree(n, 0);\n for (const auto& r: roads) {\n degree[r[0]]++;\n degree[r[1]]++;\n }\n sort(degree.rbegin(), degree.rend());\n long lo... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "/*\n Label our nodes such that\n*/\n#include <ranges>\n\nnamespace rng = std::ranges;\n\nclass Solution {\npublic:\n long long maximumImportance(size_t n, const vector<vector<int>>& roads) {\n std::vector<size_t> cities(n);\n std::vector<size_t> cityFreq(n, 0);\n\n // fill out ci... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n long long ans = 0;\n vector<int> degree(n,0);\n vector<int> value(n,0);\n\n vector<pair<int,int>> vec(n);\n int r = roads.size();\n\n\n //filling the degree array\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "#include <vector>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n // Vector to store the degree of each city\n vector<int> degree(n, 0);\n\n // Count the degree of each city\n for ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<long long> inOutDegrees(n, 0);\n int index = 0;\n \n for (auto &r : roads) {\n inOutDegrees[r[0]]++;\n inOutDegrees[r[1]]++;\n }\n sort(in... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\n typedef long long ll;\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n //unordered_map<int, unordered_set<int,int>> adj;\n vector<int> vec(n,0);\n for(int i=0; i<roads.size();i++){\n vec[roads[i][0]]++;\n vec[roads[i][1]]++;... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> city(n,0);\n for(auto& road:roads){\n city[road[0]]++;\n city[road[1]]++;\n }\n vector<pair<int,int>> st;\n for(int i=0;i<n;i++){\n st.push_back({... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> city(n,0);\n for(auto& road:roads){\n city[road[0]]++;\n city[road[1]]++;\n }\n vector<pair<int,int>> st;\n for(int i=0;i<n;i++){\n st.push_back({... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> adj(n); \n for(auto& road : roads) {\n adj[road[0]]++;\n adj[road[1]]++; \n }\n\n priority_queue<long long> pq; \n for(int val : adj) {\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<pair<int, int>> degree;\n for(int i=0;i<n;++i) {\n degree.push_back(make_pair(0, i));\n }\n for(int i=0;i<roads.size();++i) {\n degree[roads[i][0]].firs... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n long long size=roads.size();\n vector<long long> adj(n);\n for(int i=0;i<size;i++){ \n adj[roads[i][0]]++;\n adj[roads[i][1]]++;\n }\n priority_queue... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& a) {\n vector<vector<int>> adj(n);\n vector<int> degree(n);\n for (int i=0; i<a.size(); i++) {\n int from = a[i][0];\n int to = a[i][1];\n degree[from]++;\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& a) {\n vector<vector<int>> adj(n);\n vector<int> degree(n);\n for (int i=0; i<a.size(); i++) {\n int from = a[i][0];\n int to = a[i][1];\n degree[from]++;\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n\n // define sum of roads to get maximum where:\n // (1) cities with higher indegree have higher importance\n // (2) tie-breakers are made by the importance of the cities excident\n... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> indegree(n);\n for(int i=0;i<roads.size();i++){\n indegree[roads[i][0]]+=1;\n \n indegree[roads[i][1]]+=1;\n \n }\n vector<pai... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> degree(n, 0);\n\n \n for (auto& road : roads) {\n degree[road[0]]++;\n degree[road[1]]++;\n }\n\n \n vector<pair<int, int>> num1;\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n\n // define sum of roads to get maximum where:\n // (1) cities with higher indegree have higher importance\n // (2) tie-breakers are made by the importance of the cities excident\n... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> indegree(n,0);\n for(auto& road : roads) {\n indegree[road[0]]++;\n indegree[road[1]]++;\n }\n\n priority_queue<pair<int,int>> pq;\n for(int... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<pair<int,int>> vec;\n vector<int> v(n,0);\n for(int i=0;i<roads.size();i++)\n {\n v[roads[i][0]]++;\n v[roads[i][1]]++;\n }\n for(int i=0;... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "#include <vector>\n#include <algorithm>\n#include <unordered_map>\nusing namespace std;\n\nclass Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n // Step 1: Calculate the degree of each city\n vector<int> degree(n, 0);\n for (const auto& road ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "\nclass Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n // Step 1: Initialize the degree count for each city and the total importance\n vector<int> degree(n, 0); // degree[i] will hold the number of roads connected to city i\n long long tota... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> v(n, 0);\n for(int i=0; i<roads.size(); i++)\n {\n v[roads[i][0]]++, v[roads[i][1]]++;\n }\n\n vector<pair<int, int>> p; // roads and index\n fo... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<pair<long,long>>indegree;\n for(long i=0;i<n;i++){\n indegree.push_back({0,i});\n }\n for(long i=0;i<roads.size();i++){\n indegree[roads[i][0]].first++;... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> count (n, 0);\n // cout << 1 << endl;\n for (int i = 0; i < roads.size(); ++i)\n {\n ++count[roads[i][0]];\n ++count[roads[i][1]];\n }\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<long long> deg(n);\n for (auto & road : roads) {\n int u = road[0], v = road[1];\n ++deg[u];\n ++deg[v];\n }\n vector<pair<long long, int>> p... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n vector<int> degree(n,0);\n for(auto i:roads){\n degree[i[0]]++;\n degree[i[1]]++... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 1 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> road(n,0);\n for(auto a:roads){\n road[a[0]]++;\n road[a[1]]++;\n }\n sort(road.begin(),road.end());\n long long int ans=0;\n for(int... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 2 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n long long candidateValue = n;\n unordered_map<int,int> degree;\n for (int i = 0; i < roads.size(); i++) {\n degree[roads[i][0]]++;\n degree[roads[i][1]]++;\n }... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 2 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n unordered_map <int, int> ump;\n for(int i=0; i<roads.size(); i++){\n int src = roads[i][0];\n int dest = roads[i][1];\n ump[src]++;\n ump[dest]++;\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 2 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n unordered_map<int, int> adj;\n for(int i=0 ; i<roads.size() ; i++){\n adj[roads[i][0]]++;\n adj[roads[i][1]]++;\n }\n priority_queue<int> pq;\n for(int ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 2 | {
"code": "class Solution {\ntypedef long long ll;\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n map<int,int> mp;\n for(auto &road : roads){\n mp[road[0]]++;\n mp[road[1]]++;\n }\n vector<int> v(n,0);\n iota(begin(v), end(v),0... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 2 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n long long res = 0;\n unordered_map<int, int> mp;\n for (auto& r : roads) {\n mp[r[0]]++;\n mp[r[1]]++;\n }\n priority_queue<pair<long long, int>> pq;\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 2 | {
"code": "class Solution {\npublic:\n\n static bool cmp(const pair<int,int>& a, const pair<int,int>& b)\n {\n return a.second < b.second;\n }\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n \n\n vector<int> v(n,0);\n\n for(int i=0;i<roads.size();i++)\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 2 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n long long sum=0;\n vector<vector<int>>adj(n);\n vector<long long> indegree(n);\n for (auto i : roads){\n indegree[i[0]]++;\n indegree[i[1]]++;\n }\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 2 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> deg(n, 0) ;\n for(auto &r : roads){\n deg[r[0]]++ ; deg[r[1]]++ ;\n }\n\n vector<pair<int , int>> p ;\n for(int i=0 ; i<n ; i++){\n p.push_b... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 2 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int>indeg(n,0);\n for(int i=0;i<roads.size();i++)\n {\n indeg[roads[i][0]]++;\n indeg[roads[i][1]]++;\n }\n\n vector<pair<int,int>>indegNode;\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 2 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<vector<int>>adj(n);\n vector<int>degree(n,0);\n for(auto x:roads)\n {\n degree[x[0]]++;\n degree[x[1]]++;\n }\n sort(degree.rbegin(),degre... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n long long ans = 0;\n vector<long long> deg (n,0);\n for(auto it : roads){\n deg[it[0]]++;\n deg[it[1]]++;\n }\n priority_queue<pair<long long,int>> pq;\... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& ed) {\n long long ans = 0;\n vector<vector<int>> adj(n);\n vector<int> v(n,0);\n for(int i = 0; i<ed.size(); i++){\n adj[ed[i][0]].push_back(ed[i][1]);\n adj[ed[i][1]].pu... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<vector<int>> adj(n);\n vector<int> freq;\n for(int i = 0; i < roads.size(); i++) {\n adj[roads[i][0]].push_back(roads[i][1]);\n adj[roads[i][1]].push_back(road... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n\n unordered_map<int, int> degree;\n unordered_map<int, int> imp;\n long long sum = 0;\n\n for(int i = 0; i < roads.size(); i++) {\n degree[roads[i][1]]++;\n de... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int>adj[n];\n unordered_map<int,int>mp;\n for(int i=0;i<roads.size();i++)\n {\n mp[roads[i][0]]++;\n mp[roads[i][1]]++;\n adj[roads[i][0]].pu... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<long long int>indegree(n,0);\n for(int i=0;i<roads.size();i++){\n indegree[roads[i][0]]++;\n indegree[roads[i][1]]++;\n }\n\n vector<pair<long long int,... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<vector<int>>adj(n,vector<int>());\n for(int i=0;i<roads.size();i++){\n adj[roads[i][0]].push_back(roads[i][1]);\n adj[roads[i][1]].push_back(roads[i][0]);\n }\... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<vector<int>> adj(n);\n for (const auto& it : roads) {\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push_back(it[0]);\n }\n vector<pair<int, int>> weights... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n std::unordered_map<int, int> cityToRoadQty;\n for (const std::vector<int>& road : roads) {\n ++cityToRoadQty[road[0]];\n ++cityToRoadQty[road[1]];\n }\n std::v... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> inroads(n, 0);\n vector<vector<int>> adj(n);\n for (auto& i : roads) {\n inroads[i[0]]++;\n inroads[i[1]]++;\n adj[i[0]].push_back(i[1]);\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n map<int,int> maps;\n \n for(auto road:roads) {\n maps[road[0]] ++;\n maps[road[1]] ++;\n }\n \n vector<long long> order;\n for(auto city:m... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<vector<long long>> adj(n);\n for(int i=0;i<roads.size();i++)\n {\n adj[roads[i][0]].push_back(roads[i][1]);\n adj[roads[i][1]].push_back(roads[i][0]);\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> adj[n];\n for (auto x:roads){\n int u = x.front(), v = x.back();\n adj[u].push_back(v);\n adj[v].push_back(u);\n }\n priority_queue<int> q;\n \n for (int ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int>adj[n];\n for(auto it:roads){\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push_back(it[0]);\n }\n vector<int>vec;\n for(int i=0;i<n;i++){\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n static bool cmd(int a, int b){\n return a>b;\n }\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int>adj[n];\n\n for(auto x : roads){\n adj[x[0]].push_back(x[1]);\n adj[x[1]].push_back(x[0]);\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n // count node\n priority_queue<long long > pq;\n vector<int> adj[n];\n for (auto it:roads){\n int n1=it[0];\n int n2=it[1];\n adj[n1].push_back(n2... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\nstatic bool comp(pair<int,int>&p,pair<int,int>&b){\n return p.second>b.second;\n}\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n // int n=roads.size();\nvector<int>adj[n];\n for(auto it:roads){\n int f=it[0];\n int s... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n unordered_map<int,int> mp;\n for(auto it: roads){\n mp[it[0]]++;\n mp[it[1]]++;\n }\n\n set<pair<int,int>, greater<pair<int,int>>> st;\n for(auto it: mp... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> adj[n]; \n for(int i=0 ; i<roads.size() ; i++){\n adj[roads[i][1]].push_back(roads[i][0]) ;\n adj[roads[i][0]].push_back(roads[i][1]) ;\n }\n pri... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "\nclass Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n std::vector<std::pair<int, std::vector<int>>> map(n);\n for (int i = 0; i < n; ++i)\n map[i].first = i;\n\n for (auto& r : roads)\n {\n map[r[0]].second.push... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<vector<int>> graph(n, vector<int>());\n\n for(auto road:roads)\n {\n graph[road[0]].push_back(road[1]);\n graph[road[1]].push_back(road[0]);\n }\n\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n map<int,vector<int>> mp;\n \n for(int i = 0 ; i < roads.size();i++){\n mp[roads[i][0]].push_back(roads[i][1]);\n mp[roads[i][1]].push_back(roads[i][0]);\n }\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n \n int degree[n];\n int values[n];\n memset(degree,0,sizeof(degree));\n\n for(auto edge : roads){\n degree[edge[0]]++;\n degree[edge[1]]++;\n }\n... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n map<int,int>freq;\n for(auto i:roads)\n {\n freq[i[0]]+=1;\n freq[i[1]]+=1;\n }\n \n priority_queue<pair<int,int>>store;\n for(auto i:freq... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\nvector<vector<int>> vec(n);\n map<int, int>map;\n for(int i = 0; i < roads.size(); i++)\n {\n vec[roads[i][0]].push_back(roads[i][1]);\n vec[roads[i][1]].push_back(roa... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\nvector<vector<int>> vec(n);\n map<int, int>map;\n int accessed = 0;\n for(int i = 0; i < roads.size(); i++)\n {\n accessed = accessed + 2;\n vec[roads[i][0]].pu... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n long long ans = 0;\n map<int, int> mpp;\n for(auto vect: roads){\n mpp[vect[0]]++;\n mpp[vect[1]]++;\n }\n vector<pair<int, int>> sorted_arr;\n f... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n static bool cmp(pair<int,int>p,pair<int,int>q){\n return p.second>q.second;\n }\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int>ind(n,0);\n for(auto i:roads){\n ind[i[0]]++;\n ind[i[1]]++;\n ... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n\tlong long maximumImportance(int n, vector<vector<int>>& roads) {\n\t\tstd::map<int, int> cityRoads;\n\t\tstd::unordered_map<int, int> weights;\n\n\t\tfor (auto r : roads) {\n\t\t\tif (cityRoads.find(r[0]) == cityRoads.end()) cityRoads.emplace(r[0], 0);\n\t\t\tif (cityRoads.find... |
2,379 | <p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are also given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidi... | 3 | {
"code": "class Solution {\npublic:\n long long maximumImportance(int n, vector<vector<int>>& roads) {\n vector<int> degree(n, 0);\n vector<vector<int>> adj(n);\n for(auto it: roads){\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push_back(it[0]);\n degree[it[0]... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 0 | {
"code": "class Solution {\npublic:\n static vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n constexpr uint16_t IMASK = (1u << 10) - 1u;\n const uint16_t n = names.size();\n for (uint16_t i = 0; i < n; i++)\n heights[i] = (heights[i] << 10) + i;\n ... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 0 | {
"code": "class Solution {\npublic:\n static vector<string> sortPeople(vector<string>& names, const vector<int>& heights) {\n const uint16_t n = names.size();\n uint16_t idxs[n];\n iota(idxs, idxs + n, 0);\n sort(idxs, idxs + n, [&heights](const auto i, const auto j) __attribute__((alw... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 0 | {
"code": "class Solution {\npublic:\n static vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n constexpr uint16_t IMASK = (1u << 10) - 1u;\n const uint16_t n = names.size();\n for (uint16_t i = 0; i < n; i++)\n heights[i] = (heights[i] << 10) + i;\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.