id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"code": "//somdeday he will say \"you did well\";\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 3 | {
"code": "\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, Tre... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,148 | <p>There are <code>n</code> <strong>availabe </strong>seats and <code>n</code> students <strong>standing</strong> in a room. You are given an array <code>seats</code> of length <code>n</code>, where <code>seats[i]</code> is the position of the <code>i<sup>th</sup></code> seat. You are also given the array <code>student... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\nvoid parse_input_and_solve(std::ofstream& out, s... |
2,148 | <p>There are <code>n</code> <strong>availabe </strong>seats and <code>n</code> students <strong>standing</strong> in a room. You are given an array <code>seats</code> of length <code>n</code>, where <code>seats[i]</code> is the position of the <code>i<sup>th</sup></code> seat. You are also given the array <code>student... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\nvoid parse_input_and_solve(std::ofstream& out, s... |
2,148 | <p>There are <code>n</code> <strong>availabe </strong>seats and <code>n</code> students <strong>standing</strong> in a room. You are given an array <code>seats</code> of length <code>n</code>, where <code>seats[i]</code> is the position of the <code>i<sup>th</sup></code> seat. You are also given the array <code>student... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = []() {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\nvoid parse_input_and_solve(std::ofstream& out, ... |
2,148 | <p>There are <code>n</code> <strong>availabe </strong>seats and <code>n</code> students <strong>standing</strong> in a room. You are given an array <code>seats</code> of length <code>n</code>, where <code>seats[i]</code> is the position of the <code>i<sup>th</sup></code> seat. You are also given the array <code>student... | 0 | {
"code": "class Solution {\npublic:\n int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n int count=0;\n sort(seats.begin(), seats.end());\n sort(students.begin(), students.end());\n for(int i=0;i<students.size();i++){\n count += abs(seats[i] - students[i]);\n ... |
2,148 | <p>There are <code>n</code> <strong>availabe </strong>seats and <code>n</code> students <strong>standing</strong> in a room. You are given an array <code>seats</code> of length <code>n</code>, where <code>seats[i]</code> is the position of the <code>i<sup>th</sup></code> seat. You are also given the array <code>student... | 0 | {
"code": "class Solution {\npublic:\n int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n sort (seats.begin(), seats.end());\n sort (students.begin(), students.end());\n int ans = 0;\n\n for (int i = 0; i < seats.size(); i++) {\n ans += abs(seats[i] - students[... |
2,148 | <p>There are <code>n</code> <strong>availabe </strong>seats and <code>n</code> students <strong>standing</strong> in a room. You are given an array <code>seats</code> of length <code>n</code>, where <code>seats[i]</code> is the position of the <code>i<sup>th</sup></code> seat. You are also given the array <code>student... | 0 | {
"code": "class Solution {\npublic:\n int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n sort(seats.begin(),seats.end());\n sort(students.begin(),students.end());\n int ans=0;\n int moves=0;\n int n=seats.size();\n for(int i=0;i<n;i++){\n int dif... |
2,148 | <p>There are <code>n</code> <strong>availabe </strong>seats and <code>n</code> students <strong>standing</strong> in a room. You are given an array <code>seats</code> of length <code>n</code>, where <code>seats[i]</code> is the position of the <code>i<sup>th</sup></code> seat. You are also given the array <code>student... | 0 | {
"code": "class Solution {\npublic:\n int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n sort(seats.begin(), seats.end());\n sort(students.begin(), students.end());\n int ans = 0;\n for (int i = 0; i < seats.size(); ++i) {\n ans += abs(seats[i] - students[i]);... |
2,148 | <p>There are <code>n</code> <strong>availabe </strong>seats and <code>n</code> students <strong>standing</strong> in a room. You are given an array <code>seats</code> of length <code>n</code>, where <code>seats[i]</code> is the position of the <code>i<sup>th</sup></code> seat. You are also given the array <code>student... | 0 | {
"code": "class Solution {\npublic:\n int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n sort(seats.begin(),seats.end());\n sort(students.begin(),students.end());\n int ans=0;\n int moves=0;\n int n=seats.size();\n for(int i=0;i<n;i++){\n int dif... |
2,148 | <p>There are <code>n</code> <strong>availabe </strong>seats and <code>n</code> students <strong>standing</strong> in a room. You are given an array <code>seats</code> of length <code>n</code>, where <code>seats[i]</code> is the position of the <code>i<sup>th</sup></code> seat. You are also given the array <code>student... | 0 | {
"code": "class Solution {\npublic:\n int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n int sum=0;\n int n=seats.size();\n sort(seats.begin(),seats.end());\n sort(students.begin(),students.end());\n for(int i=0;i<n;i++){\n if(seats[i]>students[i]){\n ... |
2,148 | <p>There are <code>n</code> <strong>availabe </strong>seats and <code>n</code> students <strong>standing</strong> in a room. You are given an array <code>seats</code> of length <code>n</code>, where <code>seats[i]</code> is the position of the <code>i<sup>th</sup></code> seat. You are also given the array <code>student... | 1 | {
"code": "class Solution {\npublic:\n int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n sort(seats.begin(),seats.end());\n sort(students.begin(),students.end());\n int ans=0;\n int moves=0;\n int n=seats.size();\n for(int i=0;i<n;i++){\n int dif... |
2,148 | <p>There are <code>n</code> <strong>availabe </strong>seats and <code>n</code> students <strong>standing</strong> in a room. You are given an array <code>seats</code> of length <code>n</code>, where <code>seats[i]</code> is the position of the <code>i<sup>th</sup></code> seat. You are also given the array <code>student... | 1 | {
"code": "class Solution {\npublic:\n int minMovesToSeat(vector<int>& seats, vector<int>& students) {\n \n sort(seats.begin(), seats.end());\n sort(students.begin(), students.end());\n\n int ans=0;\n\n for(int i=0;i<seats.size(); i++){\n ans+= abs(seats[i]- students[i... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "\n\n\n\nint _ = [](){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); return 0; }();\n\nclass Solution {\npublic:\n bool winnerOfGame(string &colors) {\n int const n = colors.length();\n int a = 0, b = 0, count = 0;\n int left = 0, right = 0;\n while(left < n) {... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(std::string& colors) {\n auto left1 = colors.begin();\n auto left2 = colors.begin();\n int alica = 0;\n int bob = 0;\n bool ans = false;\n while (left1 != colors.end() || left2 != colors.end()) {\n whi... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "static const int speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\n\nclass Solution {\npublic:\n bool winnerOfGame(std::string& colors) {\n auto left1 = colors.begin();\n auto left2 = colors.begin();\n int alica = 0;\n int bob = 0;\n bool ans = false... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "const int _ = [](){\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n return 0;\n}();\nclass Solution {\npublic:\n bool winnerOfGame(string& colors) {\n int alice = 0, bob = 0, cnt = 1;\n\n for (int j = 1; j < colors.size(); j++) {\n if (colors[j] == colors[j - 1... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(const string& s) {\n array<int, 2> count;\n const int n = (int)s.size();\n\n for (int i = 0; i < n-2; ++i) {\n if (s[i] == s[i+1] && s[i+1] == s[i+2])\n count[s[i]-'A']++;\n }\n return count[0] > c... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string &colors) {\n int n=colors.size();\n int na=0,nb=0;\n for(int i=1;i<n-1;i++){\n if(colors[i]=='A'){\n if(colors[i-1]=='A'&&colors[i+1]=='A')na++;\n }\n else{\n if(color... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int n=colors.size();\n int alice=0;\n int bob=0;\n for(int i=1;i<n-1;i++)\n {\n if(colors[i]==colors[i-1]&& colors[i]==colors[i+1])\n {\n if(colors[i]=='A')\n {\n ... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int count = 0;\n int lenA = 0, lenB = 0;\n\n for(auto ch : colors) {\n if(ch == 'A') {\n lenA++;\n if(lenA > 2) \n count++; \n lenB = 0; \n ... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int a=0,b=0;\n for(int i=1;i<colors.size()-1;i++){\n if(colors[i]=='A' && colors[i]==colors[i-1] && colors[i]==colors[i+1])a++;\n else if(colors[i]=='B' && colors[i]==colors[i-1] && colors[i]==colors[i+1... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int n = colors.size();\n if (n < 3)return false;\n\n int alice = 0, bob = 0;\n\n for(int i = 1; i < n; ++i){\n int j = i-1;\n while(i < n && colors[i] == colors[i-1]){\n ++i;... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int aIndex =0;\n int bIndex = 0;\n int aCounter = 0;\n int bCounter =0;\n bool result = false;\n \n while(true)\n {\n int i = 0;\n for( i=aIndex; i<colors.length... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int aliceMoves = 0, bobMoves = 0;\n for (int i = 1; i < colors.size() - 1; i++) {\n if (colors[i] == 'A' && colors[i - 1] == 'A' && colors[i + 1] == 'A') {\n aliceMoves++;\n }\n ... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 0 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int countA=0, countB=0;\n for(int i=1; i< colors.size()-1;i++){\n if(colors[i]=='A' && colors[i-1]=='A' && colors[i+1]=='A')\n countA++;\n else if(colors[i]=='B' && colors[i-1]=='B' && col... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 1 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int aliceMoves = 0; // Count of moves Alice can make\n int bobMoves = 0; // Count of moves Bob can make\n \n // Traverse through the string to count moves\n for (int i = 1; i < colors.size() - 1; i++)... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 1 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int n = colors.size();\n int alice = 0;\n int bob = 0;\n\n for(int i = 1; i < n-1; i++){\n if(colors[i-1] == 'A' && colors[i] == 'A' && colors[i+1] == 'A'){\n alice++;\n ... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 3 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int alice =0;\n int bob =0;\n\n int n=colors.length();\n for(int i=1;i<=n-2;i++){\n if(colors[i]== colors[i-1] && colors[i]==colors[i+1]){\n if(colors[i]=='A') alice++;\n ... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 3 | {
"code": "class Solution {\npublic:\n int n;\n bool winnerOfGame(string colors) {\n n = colors.length();\n vector<bool> as(n,false) , bs(n,false);\n for(int i = 1 ; i < n-1 ; i++){\n if(colors[i-1] == 'A' && colors[i+1] == 'A' && colors[i] == 'A')as[i] = true;\n if(co... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 3 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n // bool check=false;\n // int cnt=0;\n // char cur_check='A';\n // while(check==false){\n // bool changed=false;\n // for(int i=1;i<colors.size()-1;i++){\n // if(colors[i-1]=... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 3 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int n = colors.size();\n int a = 0;\n int b = 0;\n for(int i = 0; i < n-2; i++){\n if(colors.substr(i, 3) == \"AAA\") a++;\n if(colors.substr(i, 3) == \"BBB\") b++;\n }\n retu... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 3 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int count_AAA=0;\n int count_BBB=0;\n for(int i=0;i<colors.size();i++){\n if(colors.substr(i,3)==\"AAA\") count_AAA++;\n else if(colors.substr(i,3)==\"BBB\") count_BBB++;\n\n }\n ret... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 3 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int cntA = 0,cntB = 0;\n for(int i=0;i<colors.size();i++){\n if(colors[i]=='A')\n if(colors.substr(i,3)==\"AAA\") cntA++;\n if(colors[i]=='B')\n if(colors.substr(i,3)==\"BBB... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 3 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int alice=0;\n int bob=0;\n for(int i =1;i<colors.size()-1;i++){\n if(colors.substr(i-1,3)==\"AAA\") alice++... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 3 | {
"code": "class Solution {\npublic:\n bool winnerOfGame(string colors) {\n int a_score = 0, b_score = 0, state;\n if(colors[0] == 'A') {\n state = 0;\n }\n else {\n state = 1;\n }\n\n string str = \"\";\n for(int i=0; i<colors.size(); i++) {\n... |
2,149 | <p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>
<p>Alice and Bo... | 3 | {
"code": "class Solution {\n\npublic:\n bool winnerOfGame(string colors) {\n int player[2]={0};\n int n=colors.size();\n if (n<3) return 0;//Be careful for edge cases\n int prev2=colors[0], prev1=colors[1];\n\n #pragma unroll\n for(char& c: colors.substr(2)) {\n if (c==prev1 && c==prev2) pl... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nint s = 1, cnt = 0, head[10005], minDis[10005], secDis[10005];\n\nstruct edge {\n int to;\n int next;\n} e[40005];\n\nstruct node {\n int id, dis;\n node(int _id, int _dis) : id(_id), dis(_dis) {}\n friend bool operator > (const node &a, cons... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "constexpr static int N = 1e4 + 10, M = 4 * N, INF = 0x3f3f3f3f;\nint dist1[N], dist2[N], he[N], ne[M], e[M], idx;\nvoid add(int a, int b) {\n e[idx] = b;\n ne[idx] = he[a];\n he[a] = idx;\n idx++;\n}\n\n\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int ti... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "#define ll long long\n#define ull unsigned long long\n#define lll __int128\n#define rep(i,n,N) for(int i=(n);i<=(N);++i)\n#define For(i,n,N) for(int i=(n);i< (N);++i)\n#define rap(i,n,N) for(int i=(n);i>=(N);--i)\n#define rip(i,n,N,V) for(int i=(n);i<=(N);i+=V)\n#define mp make_pair\n#define pb push_back\n... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n const int inf = 0x3f3f3f3f;\n struct edge\n {\n int to,ne,w;\n }e[40005];\n void add(int u,int v)\n {\n e[++id] = {v,h[u]};\n h[u] = id;\n }\n int h[10005],id = 0;\n int secondMinimum(int n, vector<vector<int>>& edges, int time, in... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n const int inf = 0x3f3f3f3f;\n struct edge\n {\n int to,ne,w;\n }e[40005];\n void add(int u,int v)\n {\n e[++id] = {v,h[u]};\n h[u] = id;\n }\n int h[10005],id = 0;\n int secondMinimum(int n, vector<vector<int>>& edges, int time, in... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "const int maxN = 1e4 + 5;\nusing pii = pair<int, int>;\nvector<int> adj[maxN];\nint dist[maxN][2];\n\nclass Solution {\npublic:\n inline int calculate_time_taken(int steps_taken, int time, int change) {\n int ans = 0;\n for (int i = 0; i < steps_taken; ++i) {\n int green_light =... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n static const int N = 10010, M = 4 * N, INF = 0x3f3f3f3f;\n int idx = 0;\n int h[N], e[M], ne[M];\n int dis1[N], dis2[N];\n\n void add(int a, int b){\n e[idx] = b;\n ne[idx] = h[a];\n h[a] = idx++;\n }\n int secondMinimum(int n, vector<ve... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "#pragma GCC optimize(\"Ofast\", \"unroll-loops\", \"omit-frame-pointer\", \"inline\")\n#pragma GCC target(\"avx,avx2,fma\")\n\nconst int maxN = 1e4 + 5;\nusing pii = pair<int, int>;\nvector<int> adj[maxN];\nint dist[maxN][2];\n\nclass Solution {\npublic:\n inline int calculate_time_taken(int steps_taken... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "const int MAXN=1e4+5;\nint c,t;\nvector<vector<int>> g;\n\nint bfs(int n)\n{\n queue<pair<int,int>> q;\n vector<int> dist1(n+1,-1);\n vector<int> dist2(n+1,-1);\n\n q.push({1,1});\n dist1[1]=0;\n\n while(!q.empty())\n {\n auto u=q.front();\n q.pop();\n\n int tt=(u.... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\n bool update(vector<vector<int>>& dist, int u, int v) {\n // 1 -> u -> v\n int f = dist[v][0];\n int s = dist[v][1];\n\n\n int n1 = dist[u][0] == INT_MAX ? INT_MAX : dist[u][0] + 1;\n int n2 = dist[u][1] == INT_MAX ? INT_MAX : dist[u][1] + 1;\n\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "static auto _ = [](){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();\n\nclass Solution {\n vector<int> start;\n vector<pair<int,int>> next; // index, v\n vector<int> first;\n vector<int> second;\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges,... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n int edgesSize = edges.size();\n \n // Create the adjacency list\n uint16_t **graph = (uint16_t **)malloc((n + 1) * sizeof(uint16_t *));\n int *connectionCount = (... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n int edgesSize = edges.size();\n \n // Create the adjacency list\n uint16_t **graph = (uint16_t **)malloc((n + 1) * sizeof(uint16_t *));\n int *connectionCount = (... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n int edgesSize = edges.size();\n \n // Create the adjacency list\n uint16_t **graph = (uint16_t **)malloc((n + 1) * sizeof(uint16_t *));\n int *connectionCount = (... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\nprivate:\n static uint waittime(const uint s, const uint16_t t, const uint16_t c) __attribute__((always_inline)) {\n uint w = 0;\n for (uint i = 0; i < s; i++) {\n const uint g = w / c;\n if (g & 1u) w = (g + 1u) * c;\n w += t;\n }\... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\nprivate:\n static uint waittime(const uint s, const uint16_t t, const uint16_t c) __attribute__((always_inline)) {\n uint w = 0;\n for (uint i = 0; i < s; i++) {\n const uint g = w / c;\n if (g & 1u) w = (g + 1u) * c;\n w += t;\n }\... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "typedef pair<int, int> Data;\nconst int INF = 1000000000;\n\nint d1[10001];\nint d2[10001];\nint f[10001];\nvector<int> adj[10001];\n\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n for (int i = 1; i <= n; i++) adj[i].clear();\n f... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\n public:\n int secondMinimum(const int n, const vector<vector<int>> &edges, const int time, const int change) {\n constexpr int source = 0;\n constexpr int second_time = 2;\n constexpr int range = 2;\n const int target = n - 1;\n vector<int> graph[n];\n for (const vecto... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\n static int const N = 10001;\n static int const M = 4 * N;\n int dir1[N], dir2[N];\n int he[N], e[M], ne[M];\n int idx = 0;\n int INF = 0x3F3F3F3F;\n using PP = pair<int, int>;\npublic:\n void add(int u, int v) {\n e[idx] = v;\n ne[idx] = he[u];\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "#pragma GCC optimize(\"Ofast\",\"inline\",\"-ffast-math\")\n#pragma GCC target(\"avx,mmx,sse2,sse3,sse4\")\ntypedef pair<int, short> pr;\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "#pragma GCC optimize(\"Ofast\",\"inline\",\"-ffast-math\")\n#pragma GCC target(\"avx,mmx,sse2,sse3,sse4\")\ntypedef pair<int, short> pr;\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "#pragma GCC optimize(\"Ofast\",\"inline\",\"-ffast-math\")\n#pragma GCC target(\"avx,mmx,sse2,sse3,sse4\")\ntypedef pair<int, short> pr;\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& _edges, int time, int change) {\n vector<int> edges[n];\n\n for(const auto &vp : _edges) {\n int u = vp[0] - 1, v = vp[1] - 1;\n edges[u].push_back(v);\n edges[v].push_back(u);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "const int mxN = 1e4+1;\n\nclass Solution {\npublic:\n vector<int> adj[mxN];\n int vis[mxN];\n int par[mxN];\n int dist[mxN];\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n memset(dist, -1, sizeof(dist));\n memset(par, -100, sizeof(par));\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n \n // https://leetcode.com/problems/second-minimum-time-to-reach-destination/discuss/1525165/C%2B%2B-Two-BFS-with-detailed-explanation\n \n int calc_time(int s, int t, int c)\n {\n int res = 0;\n \n while(s--)\n {\n res += t;... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution \n{\n public:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) \n {\n int m=edges.size();\n vector<int> total[n+1]; // the graph of the edges\n for(int i=0;i<m;i++)\n {\n total[edges[i][0]].push_back(edges[i][1]);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "const int INF = 0x3f3f3f3f;\nconst int N = 10003;\nvector<int> g[N];\nint dis[N][2];\nint vst[N];\n\nclass Solution {\n void bfs(int u, int t, int c) {\n vst[u] = 1;\n queue<int> q;\n q.push(u);\n while(!q.empty()) {\n int v = q.front();\n q.pop();\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n int cnt=0;\n queue<int>q;\n vector<int> adj[n+1];\n for(auto &edge: edges)\n {\n adj[edge[0]].push_back(edge[1]);\n adj[edge[1]].push_back(e... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt,arch=pantherlake\")\n\nusing u16 = uint16_t;\n\nclass Solution {\npublic:\n static bitset<10001> expandCircle(const vector<vector<u16>>& adjacencies, const bitset<10001>& circle) __attribute__ ((__target__ (\"avx2... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n unsigned int u, dist[10000];\n vector<int> adj[10000];\n queue<int> q;\n memset(dist, -1, n << 2);\n dist[0] = 0;\n for (auto &e: edges) {\n adj... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> adjList[n];\n for (vector<int> &edge : edges) {\n int u = edge[0] - 1, v = edge[1] - 1;\n adjList[u].emplace_back(v);\n adjList[v].emplace... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\n\nint levelOfVertex(int n, vector<int> adj[]){\n vector<int> level(n+1, 1e9);\n level[1] = 0;\n\n queue<int> q;\n q.push(1);\n\n while(!q.empty()){\n int topNode = q.front();\n q.pop();\n for(auto it: adj[topNode]){\n if(level[topNode] + 1 < ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n\n vector<int>adj[n+1];\n\n for(auto&v : edges){\n for(int i = 0 ; i < 2 ; ++i){\n adj[v[i]].push_back(v[i^1]);\n }\n }\n\n queue<int... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "inline const auto optimize = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> adj[n];\n\n for... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n bool flag[10000]{};\n unsigned int i, u, x, y, dist[10000];\n vector<int> adj[10000];\n queue<int> q;\n int meme=50;\n memset(dist, -1, n << 2);\n d... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> adj[n+1];\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 ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n\n vector<int>adj[10001];\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,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<vector<int16_t>> gr(n);\n for (const auto& e : edges) {\n gr[e[0] - 1].push_back(e[1] - 1);\n gr[e[1] - 1].push_back(e[0] - 1);\n }\n\n queu... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n \n vector<int> adj[n];\n for(int i=0;i<edges.size();i++)\n {\n int u = edges[i][0]-1;\n int v = edges[i][1]-1;\n\n adj[u].push_back(v);\... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n void print(vector<pair<int,int>>& v){\n cout<<\"here\\n\";\n for(int i=1; i<v.size(); ++i){\n cout<<i<<\"#\"<<v[i].first<<\",\"<<v[i].second<<\"$\";\n }\n cout<<\"here\\n\";\n }\n\n int secondMinimum(int n, vector<vector<int>>& edg... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "\nint solve(int n,vector<vector<int>>&adj){\n int dist[n+3];\n for(int i=0;i<=n;i++) dist[i]=1e7;\n dist[1]=0;\n queue<int> q;\n q.push(1);\n while(!q.empty())\n {\n int u=q.front();\n q.pop();\n for(int i=0;i<adj[u].size();i++)\n {\n int v=adj[u]... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n // if the shortest path from 1 to n is of length L\n // find whether there is a path of length L+1\n // there is always a path of length L+2\n \n vector<vector<in... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 0 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vector<int> adj[n + 1];\n for (auto& it : edges) {\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push_back(it[0]);\n }\n vector<int> minimum_time(n +... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 1 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n queue<pair<int, int>> Q;\n vector<bool> Status(n+1);\n vector<vector<int>> Adj(n+1);\n vector<int> Dist(n+1);\n for (auto & edge : edges)\n {\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 1 | {
"code": "class Solution {\npublic:\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change)\n {\n vector<vector<int>> adj(n);\n for(auto& edge: edges)\n {\n adj[edge[0] - 1].push_back(edge[1] - 1);\n adj[edge[1] - 1].push_back(edge[0] - 1);\n ... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 1 | {
"code": "class Solution {\npublic:\n vector<int> get_min_distances(vector<vector<int>>& G) {\n int n = G.size();\n vector<int> dist(n, 1000000);\n vector<int> visited(n);\n dist[0] = 0;\n\n std::priority_queue<std::pair<int, int>> q;\n q.emplace(0, 0);\n\n while (... |
2,171 | <p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</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>... | 1 | {
"code": "class Solution {\npublic:\n int calcTime(int t, int change, int time) {\n int i = t / change;\n if(i % 2 == 0)\n return t + time;\n return t + time + change-(t%change);\n }\n int secondMinimum(int n, vector<vector<int>>& edges, int time, int change) {\n vecto... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.