id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,833
<p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p> <p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ...
2
{ "code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) {\n vector<int> altitudes = {0};\n for (int i = 0; i <gain.size(); i++) {\n altitudes.push_back(altitudes[i]+gain[i] );\n }\n return *max_element(altitudes.begin(), altitudes.end());\n }\n};", ...
1,833
<p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p> <p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ...
3
{ "code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) {\n int n = gain.size();\n vector<int>arr(n+1);\n int maxheight = 0;\n arr[0] = 0;\n\n for(int i=1;i<n+1;i++){\n arr[i]=arr[i-1]+gain[i-1];\n maxheight = max(maxheight,arr[i]);\n ...
1,833
<p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p> <p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ...
3
{ "code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) {\n int n = gain.size();\n vector<int>pref(n+1,0);\n pref[0] = gain[0];\n for(int i = 1; i < n; i++){\n pref[i] = pref[i-1] + gain[i];\n }\n return *max_element(pref.begin(), pref.end(...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nstatic int gcd(int a, int b) {\n if (a < b) {\n return gcd(b, a);\n }\n while (b > 0) {\n const int n = a % b;\n a ...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "#pragma GCC optimize(\"Ofast\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nstatic int gcd(int a, int b) {\n if (a < b) {\n return gcd(b, a);\n }\n while (b > 0) {\n ...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n int init = [] {\n ofs...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n int init = [] {\n ofstr...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n static const int __ = [](...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n\nstatic const int __ = [](...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n\nstatic const int __ = [](...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nstatic const int __ = [](){...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str; getline(cin, str); cout << '\\n') {\n if (str.find(',') == st...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": " static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str; getline(cin, str); cout << '\\n') {\n if (str.find(',') == s...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n static const int __ = []()...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": " static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str; getline(cin, str); cout << '\\n') {\n if (str.find(',') == s...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "static const int iofast = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int ...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "static auto init = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n return nullptr;\n}();\n\nauto gcd_node_pool = array<ListNode, 4'999>{};\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "static auto init = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n return nullptr;\n}();\n\nauto gcd_node_pool = array<ListNode, 4'999>{};\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "static auto init = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n return nullptr;\n}();\n\nauto make_gcd_node_pool() {\n auto gcd_node_pool = array<ListNode*, 4'999>{};\n ranges::generate(gcd_node_pool, [](){ return new ListNode{}; });\n return gcd_node_pool;\n}\n\nauto gcd_node_pool = m...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "static auto init = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n return nullptr;\n}();\n\nauto make_gcd_node_pool() {\n auto gcd_node_pool = array<ListNode*, 4'999>{};\n ranges::generate(gcd_node_pool, [](){ return new ListNode{}; });\n return gcd_node_pool;\n}\n\nauto gcd_node_pool = m...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "static auto init = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n return nullptr;\n}();\n\nauto make_gcd_node_pool() {\n auto gcd_node_pool = array<ListNode*, 4'999>{};\n ranges::generate(gcd_node_pool, [](){ return new ListNode{}; });\n return gcd_node_pool;\n}\n\nauto gcd_node_pool = m...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "#include <algorithm>\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
2
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,903
<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p> <p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> of them.</p> <p>Return <em>the linked list after insertion</em>.</p> <p>The <strong>gre...
2
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source,\n int destination) {\n vector<bool> vec(n, false);\n sort(edges.begin(), edges.end());\n if (n == 1)\n return true;\n \n for(int i=0; i<edges.size(); ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source,\n int destination) {\n vector<bool> vec(n, false);\n sort(edges.begin(), edges.end());\n if (n == 1)\n return true;\n \n for(int i=0; i<edges.size(); ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n\n vector<int> paper;\n\n int find(int x)\n {\n if(paper[x] == x)return x;\n paper[x] = find(paper[x]);\n return paper[x];\n }\n\n void onion(int i , int j)\n {\n int in = find(i);\n int jn = find(j);\n\n if(in>jn)paper[...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class DisjointSet {\npublic:\n DisjointSet(int n) : ds(n) {\n for (int i = 0; i < n; i++) {\n ds[i] = -1;\n }\n }\n\n int find(int i) {\n if (ds[i] < 0) {\n return i;\n }\n\n return find(ds[i]);\n }\n\n void unionBySize(int x, int y) {...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n UnionFind *dsu = new UnionFind(n);\n for(const auto& edge:edges){\n dsu -> connect(edge[0], edge[1]);\n }\n return (dsu -> componentRoot(source)) == (dsu ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n UnionFind *dsu = new UnionFind(n);\n for(const auto& edge:edges){\n dsu -> connect(edge[0], edge[1]);\n }\n return (dsu -> componentRoot(source)) == (dsu ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n\n class UF\n {\n public:\n UF( int size ) {\n for( int i = 0; i < size; i++ )\n {\n storage.push_back( i );\n }\n }\n\n /// Finds root object\n int Find( int item )\n {\n int p...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "auto init = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 'c';}();\n\nclass Solution {\npublic:\n vector<int> parent, rank;\n\n int find(const int node) {\n return parent[node] == -1 ? node : parent[node] = find(parent[node]);\n }\n\n void unionFunc(const int x, const i...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n\n class DSU\n {\n public:\n vector<int> parent, rank;\n\n DSU(int n)\n {\n parent.resize(n,0);\n rank.resize(n,0);\n\n for(int i=0;i<n;i++)\n {\n parent[i...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n\n class DSU\n {\n public:\n vector<int> parent, rank;\n\n DSU(int n)\n {\n parent.resize(n,0);\n rank.resize(n,0);\n\n for(int i=0;i<n;i++)\n {\n parent[i...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class DisjointSetUnion {\n public:\n DisjointSetUnion(int n) : sets(n) {}\n void make_set(int x) {\n sets[x].representative = x;\n sets[x].size = 1;\n }\n int find_set(int x) {\n if(sets[x].representative != x)\n return (sets[x].representative = find_set(sets[x].represent...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n int find(int n,vector<int>& parent)\n {\n if(n == parent[n])\n return n;\n return parent[n] = find(parent[n],parent);\n }\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n vector<int> parent(n);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class DisjointSet{\n\n private:\n\n int size;\n vector<int> rank;\n vector<int> parent;\n\n public:\n\n DisjointSet(int size){\n \n this->size = size;\n for(int i =0;i<size;i++){\n rank.push_back(1);\n parent.push_back(i);\n }\n\n }\n\n...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class UnionFind {\n\npublic:\n\n vector<int> root;\n vector<int> rank;\n\n UnionFind(int n) {\n for(int i=0;i<n;i++) {\n root.push_back(i);\n rank.push_back(1);\n }\n }\n\n int find(int x) {\n if (x==root[x]) return x;\n return root[x] = find...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n vector<int> dsu;\n void init() {\n dsu.resize(200001);\n for(int c1=0;c1<200001;c1++) \n dsu[c1] = c1;\n \n return;\n }\n\n int parent(int a) {\n while(a!=dsu[a]) {\n dsu[a] = dsu[dsu[a]];\n a = dsu[...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n \n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n int parent[n];\n \n\n for (int i = 0; i < n; ++i)\n {\n parent[i] = i; \n }\n\n for (vector<int> edge : edges)\n {\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n \n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n int parent[n];\n \n\n for (int i = 0; i < n; ++i)\n {\n parent[i] = i; \n }\n\n for (vector<int> edge : edges)\n {\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class DisjointSet\n{\n public:\n vector<int> par, size;\n DisjointSet(int n)\n {\n par.resize(n);\n size.resize(n, 1);\n for (int i = 0; i < n; i++)\n {\n par[i] = i;\n }\n }\n int find(int a)\n {\n if (a == par[a]) return a;\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class DisjointSet{\npublic:\n vector<int> parent,size;\n DisjointSet(int n){\n parent.resize(n+1,0);\n size.resize(n+1,1);\n for(int i=0;i<=n;i++){\n parent[i]=i;\n }\n }\n\n int findUPar(int node){\n if(node==parent[node]){\n return node...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n ios_base::sync_with_stdio(false);\n cin.tie(0); cout.tie(0);\n \n int parent[n], size[n];\n make_set(parent, size, n);\n for (auto e : edges) {\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "// clang-format off\nstatic const auto io_sync_off = []() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();\n#define tT template<typename T>\n#define tAB template<typename A, typename B>\n#define Ti typename T::iterator\n#define Tv typename T::value_type\n#define Tk typenam...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "// clang-format off\nstatic const auto io_sync_off = []() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();\n#define tT template<typename T>\n#define tAB template<typename A, typename B>\n#define Ti typename T::iterator\n#define Tv typename T::value_type\n#define Tk typenam...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n int find(int i) {\n if(root[i] == i) return i;\n int rt = find(root[i]);\n root[i] = rt;\n return rt;\n }\n\n void join(int n, vector<vector<int>>& edges) {\n root.clear();\n for (int i = 0; i < n; i++) root.push_back(i);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n vector<int> parent;\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n parent.resize(n);\n for(int i = 1; i < n; i++){\n parent[i] = i;\n }\n\n for(auto edge: edges) {\n setUnionRepresentiv...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n\ntemplate < typename T = int, int Base = 1 > struct DSU {\n \n vector < T > parent, Gsize, nxt, tail, pos, roots;\n\n DSU(int MaxNodes){\n parent = Gsize = roots = tail = pos = nxt = vector < T > (MaxNodes + Base);\n for(int i = Base; i < MaxNodes + Base; ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool dfs(int root,int &n,vector<vector<int>>&graph,int &dest,vector<int>&vis){\n vis[root] = 1;\n if(root == dest)return true;\n\n for(int child : graph[root]){\n if(!vis[child]){\n bool ans = dfs(child,n,graph,dest,vis);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n std::vector<int> adj[n];\n\n for (const std::vector<int>& edge: edges) {\n adj[edge[0]].push_back(edge[1]);\n adj[edge[1]].push_back(edge[0]);\n }\n\n...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n std::vector<int> adj[n];\n\n for (const std::vector<int>& edge: edges) {\n adj[edge[0]].push_back(edge[1]);\n adj[edge[1]].push_back(edge[0]);\n }\n\n...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, std::vector<std::vector<int>>& edges, int source, int destination) {\n if (source == destination) {\n return true;\n }\n\n // Create adjacency list\n std::vector<int> adj[n];\n for (const auto& edge : edges) ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n std::vector<int> adj[n];\n\n for (const std::vector<int>& edge: edges) {\n adj[edge[0]].push_back(edge[1]);\n adj[edge[1]].push_back(edge[0]);\n }\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n if(source==destination)\n return true;\n vector<int>adj[n];\n int i;\n for(i=0;i<edges.size();i++) \n {\n adj[edges[i][1]].push_back(edges[i][0]...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n vector<int> adj[200000];\n int visited[200000];\n\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n if (source == destination) return true;\n if (edges.size() == 0) return false;\n for (int i = 0; i < edges.size();...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool bfs(int source, int dest, vector<int> adj[], vector<int> &visit)\n {\n queue<int> q;\n\n if(visit[source]==0)\n {\n q.push(source);\n visit[source]=1;\n\n while(!q.empty())\n {\n int node ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n vector<int>adj[n];\n for(int i =0;i<edges.size();i++)\n {\n adj[edges[i][0]].push_back(edges[i][1]);\n adj[edges[i][1]].push_back(edges[i][0]);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n vector<int>dist(n,1e9);\n dist[source]=0;\n vector<pair<int,int>>adj[n];//adjacency list\n for(auto &x:edges){\n int u=x[0];\n int v=x[1];\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int src, int dest) {\n vector<int>adj[n];\n for(int i=0;i<edges.size();i++){\n adj[edges[i][0]].push_back(edges[i][1]);\n adj[edges[i][1]].push_back(edges[i][0]);\n }\n vector<...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool vis[200005];\n vector<int>v[200005];\n void dfs(int source)\n {\n vis[source]=true;\n for(int child:v[source])\n {\n if(!vis[child])\n {\n dfs(child);\n }\n }\n }\n bool validPath(...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n static const int N = (2*1e5)+5; \n bool visited[N];\n vector <int> v[N];\n\n void dfs(int src){\n visited[src] = true;\n for(int child : v[src]){\n if(!visited[child]){\n dfs(child);\n }\n }\n }\n\n bool...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n vector<int> v[200005];\n bool vis[200005];\n void dfs(int s)\n {\n vis[s]=true;\n for(int child : v[s])\n {\n if(!vis[child])\n {\n dfs(child);\n }\n }\n }\n bool validPath(int n, vecto...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution\n{\npublic:\n vector<int> v[200005];\n bool vis[200005];\n void dfs(int s)\n {\n vis[s] = true;\n for (int child : v[s])\n {\n if (!vis[child])\n {\n dfs(child);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n //sabse pehle ek function banao to traverse bfs fir check krna us bfs me dono elemets hai ki nhi agar hai to valid hai warna nhi hai\n vector<int> bfs(int n, vector<vector<int>> &edges,vector<int> &ans,int source){\n //first create an adjacency list\n vector<int> adj[n]...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n //sabse pehle ek function banao to traverse bfs fir check krna us bfs me dono elemets hai ki nhi agar hai to valid hai warna nhi hai\n vector<int> bfs(int n, vector<vector<int>> &edges,vector<int> &ans,int source){\n //first create an adjacency list\n vector<int> adj[n]...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "#include <vector>\n#include <queue>\n#include <unordered_map>\n#include <unordered_set>\nusing namespace std;\n\nclass Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) \n {\n if (source == destination) return true;\n\n // Build adjacen...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
0
{ "code": "class Solution {\npublic:\n bool bfs(vector<vector<int>>&adj,int source,int destination,vector<bool>&visited)\n {\n queue<int>q;\n q.push(source);\n visited[source]=true;\n while(q.empty()==false)\n {\n int u=q.front();\n if(u==destination) ret...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n void dfs(int node, vector<int> adj[], vector<int> &vis) {\n vis[node] = 1;\n for(auto it : adj[node]) {\n if(!vis[it]) {\n dfs(it, adj, vis);\n }\n }\n }\n bool validPath(int n, vector<vector<int>>& edges, int so...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\n bool dfs(vector<int> adj[], int src, int dest, vector<int> &vis) {\n if(src == dest) return true;\n vis[src] = 1;\n for(auto &nbr : adj[src]) {\n if(!vis[nbr]) {\n if(dfs(adj, nbr, dest, vis)) return true;\n }\n }\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n void bfs(int source,vector<int>&vis,vector<vector<int>>&graph)\n {\n queue<int>q;\n vis[source]=1;\n q.push(source);\n while(!q.empty())\n {\n int node=q.front();\n q.pop();\n for(auto node:graph[node])\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\nvoid bfs( vector<vector<int>>&adj , int src, vector<int>&visited,queue<int>&q1)\n{\n visited[src]=1;\n q1.push(src);\n while(!q1.empty())\n {\n int node = q1.front();\n q1.pop();\n for(auto&ed:adj[node])\n {\n if(!visited[ed]){\...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n vector<int> bfss(vector<vector<int>>&adj,int src,int n)\n{\n vector<bool>visited(n,false);\n queue<int>q;\n q.push(src);\n visited[src]=true;\n vector<int>bfs;\n while(!q.empty())\n {\n int fr...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n vector<int> adj[200001];\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n for (auto& edge : edges) {\n adj[edge[0]].push_back(edge[1]);\n adj[edge[1]].push_back(edge[0]);\n }\n queue<int> q;\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n std::vector<int> adj[n];\n\n for (const std::vector<int> edge: edges) {\n adj[edge[0]].emplace_back(edge[1]);\n adj[edge[1]].emplace_back(edge[0]);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n if (source == destination) {\n return true;\n }\n\n std::vector<int> adj[n];\n\n for (const std::vector<int> edge: edges) {\n adj[edge[0]].empl...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n vector<int> adj[n];\n for(auto edge:edges){\n adj[edge[0]].push_back(edge[1]);\n adj[edge[1]].push_back(edge[0]);\n }\n queue<int> bfs;\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n /* bool recHelper(vector<vector<int>>& myMap, vector<bool>& visited, int\n start, int end){ if(start == end) return true; if(visited[start]) return\n false; visited[start] = true; for(auto &node : myMap[start]){\n if(recHelper(myMap, visited, node, end...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n\n // struct graph {\n // int val;\n // vector<graph*> edges;\n // };\n\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n vector<vector<int>> graph(n);\n for(int i=0; i< edges.size(); i++) {\n grap...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "\n#include <vector>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int nodes;\n vector<int> vis;\n vector<vector<int>> adj_list;\n\n void dfs(int node) {\n vis[node] = 1;\n for (int neighbor : adj_list[node]) {\n if (!vis[neighbor])\n dfs(neighbor...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int src, int dst) {\n ios::sync_with_stdio(0);\n cin.tie(0); cout.tie(0);\n vector<int> adj[n];\n for(auto it:edges)\n {\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int src, int dst) {\n ios::sync_with_stdio(0);\n cin.tie(0); cout.tie(0);\n vector<int> adj[n];\n for(auto it:edges)\n {\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "bool bfs(vector<vector<int>> &graph, int source, int target) {\n unordered_set<int> seen;\n queue<int> q;\n q.push(source);\n seen.insert(source);\n\n while (!q.empty()) {\n int u = q.front();\n q.pop();\n if (u == target) {\n return true;\n }\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "bool bfs(vector<vector<int>> &graph, int source, int target) {\n unordered_set<int> seen;\n queue<int> q;\n q.push(source);\n seen.insert(source);\n\n while (!q.empty()) {\n int u = q.front();\n q.pop();\n if (u == target) {\n return true;\n }\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n\nbool k;\nvector<int>v[200005];\nbool vis[200005];\nvoid dfs(int s,int d)\n{\n if(s==d)\n {\n k=true;\n }\n vis[s]=true;\n for(int c:v[s])\n {\n if(!vis[c])\n {\n dfs(c,d);\n }\n }\n}\nbool validPath(int n, vector<vecto...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n vector<int> v[200005];\n bool vis[200005];\n void dfs(int src){\n vis[src]=true;\n for(auto e:v[src]){\n if(!vis[e]){\n dfs(e);\n }\n }\n }\n bool validPath(int n, vector<vector<int>>& edges, int source, in...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n \n vector<vector<int>> adjList(n, vector<int>{});\n for(auto edge : edges) {\n adjList[edge[0]].push_back(edge[1]);\n adjList[edge[1]].push_back(edge[...