From d6f8a0e83cee1efb7e63a6bdb4fa7864e9253140 Mon Sep 17 00:00:00 2001 From: Himadeepthi Date: Sun, 22 Oct 2023 15:17:36 +0530 Subject: [PATCH 1/2] This problem involves pre-computation --- Coding/C++/Pre-computation.cpp | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Coding/C++/Pre-computation.cpp diff --git a/Coding/C++/Pre-computation.cpp b/Coding/C++/Pre-computation.cpp new file mode 100644 index 00000000..2a7d61e6 --- /dev/null +++ b/Coding/C++/Pre-computation.cpp @@ -0,0 +1,43 @@ +// https://codeforces.com/problemset/problem/1807/D + +#include + +using namespace std; + +int main(){ + int t; + cin>>t; + while(t--){ + int n,q; + cin>>n>>q; + long long int a[n]; + long long int sum=0; + for(int i=0;i>a[i]; + + } + long long int pf[n+1]; + pf[0]=0; + for(int i=1;i<=n;i++){ + pf[i]=a[i-1]+pf[i-1]; + } + + for(int i=0;i>l>>r>>k; + long long int e=pf[n]-(pf[r]-pf[l-1])+k*(r-l+1); + + + if(e%2!=0){ + cout<<"YES"< Date: Sun, 22 Oct 2023 15:29:10 +0530 Subject: [PATCH 2/2] I haved added traversal algorithms --- Coding/Python/BFS and DFS in graph.py | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Coding/Python/BFS and DFS in graph.py diff --git a/Coding/Python/BFS and DFS in graph.py b/Coding/Python/BFS and DFS in graph.py new file mode 100644 index 00000000..d2dfc87b --- /dev/null +++ b/Coding/Python/BFS and DFS in graph.py @@ -0,0 +1,41 @@ +# A program to implement traversal algorithms (BFS and DFS) in the Graph. +class Graph: + def __init__(self): + self.graph = {} + def addEdge(self, u, v): + if u not in self.graph: + self.graph[u] = [] + self.graph[u].append(v) + def BFS(self, start): + visited = set() + queue = [start] + bfs_output = [] + while queue: + vertex = queue.pop(0) + if vertex not in visited: + bfs_output.append(vertex) + visited.add(vertex) + queue.extend(self.graph.get(vertex, [])) + return bfs_output + def DFS(self, start, visited=None): + if visited is None: + visited = set() + if start not in visited: + visited.add(start) + for neighbor in self.graph.get(start, []): + self.DFS(neighbor, visited) + return visited +if __name__ == '__main__': + g = Graph() + n = int(input("Enter number of edges: ")) + for i in range(n): + u, v = map(str, input("Enter edge (u v): ").split()) + g.addEdge(u, v) + print("1. BFS") + print("2. DFS") + choice = int(input("Choose traversal algorithm: ")) + start_node = input("Enter starting node: ") + if choice == 1: + print("BFS Traversal:", g.BFS(start_node)) + else: + print("DFS Traversal:", list(g.DFS(start_node))) \ No newline at end of file