20BCS5900 - Abhishek - Kumar - CC - Exp - 5
20BCS5900 - Abhishek - Kumar - CC - Exp - 5
20BCS5900 - Abhishek - Kumar - CC - Exp - 5
COMPTETIVE CODING-I
Experiment 5
Student Name: ABHISHEK KUMAR UID: 20BCS5900
Branch: C.S.E. Section/Group: 20BCS_MM_805_A
Semester: 5th Subject Code: 20CSP-314
GRAPH
2. Task to be done/ Which logistics used:
Hackerrank.com
Problem link
https://www.hackerrank.com/challenges/bfsshortreach/problem
CODE:
#include <bits/stdc++.h>
/*
* Complete the 'bfs' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts following parameters:
* 1. INTEGER n
* 2. INTEGER m
* 3. 2D_INTEGER_ARRAY edges
* 4. INTEGER s
*/
queue<int> q;
q.push(s-1);
while(!q.empty())
{
int node = q.front();
q.pop();
output[node] = level[node] * 6;
q.push(adj_node);
if(level[adj_node]==0)
level[adj_node] = level[node] + 1;
}
graph[node].clear();
}
output.erase(output.begin() + s - 1);
return output;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string q_temp;
getline(cin, q_temp);
int q = stoi(ltrim(rtrim(q_temp)));
int n = stoi(first_multiple_input[0]);
int m = stoi(first_multiple_input[1]);
vector<vector<int>> edges(m);
string edges_row_temp_temp;
getline(cin, edges_row_temp_temp);
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
edges[i][j] = edges_row_item;
}
}
string s_temp;
getline(cin, s_temp);
int s = stoi(ltrim(rtrim(s_temp)));
if (i != result.size() - 1) {
fout << " ";
}
}
fout.close();
return 0;
}
s.erase(
s.begin(),
find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
);
return s;
}
s.erase(
find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).ba
se(),
s.end()
);
return s;
}
string::size_type start = 0;
string::size_type end = 0;
start = end + 1;
}
tokens.push_back(str.substr(start));
return tokens;
}
3. Result/Output/Writing Summary:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Problem link
https://www.hackerrank.com/challenges/even-tree/problem
CODE:
#include <bits/stdc++.h>
for(auto i : data[1]){
cout << i << "\n";
compute(data, i, t_nodes, totalcount);
}
return *totalcount;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string t_nodes_edges_temp;
getline(cin, t_nodes_edges_temp);
vector<int> t_from(t_edges);
vector<int> t_to(t_edges);
t_from[i] = t_from_temp;
t_to[i] = t_to_temp;
}
fout.close();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
return 0;
}
s.erase(
s.begin(),
find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
);
return s;
}
s.erase(
find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).ba
se(),
s.end()
);
return s;
}
string::size_type start = 0;
string::size_type end = 0;
start = end + 1;
}
tokens.push_back(str.substr(start));
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
return tokens;
}
OUTPUT:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING