Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

SIKSHAPATH

SIKSHAPATH Logo SIKSHAPATH Logo

SIKSHAPATH Navigation

  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
  • About
    1. Asked: January 5, 2022In: Programming Language

      You are given a rooted tree with N nodes, labeled 1 through n

      I'M ADMIN
      I'M ADMIN
      Added an answer on January 5, 2022 at 8:34 pm

      Run with input #include<bits/stdc++.h> using namespace std; #define int long long #define fo(i,a,b) for(int i = a; i<b ; i++) #define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define pb push_back #define M 1000000007 int mod(int x){ return ((x%M + M)%M); } int adRead more

      Run with input

      #include<bits/stdc++.h>
      using namespace std;
      #define int long long
      #define fo(i,a,b) for(int i = a; i<b ; i++)
      #define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
      #define pb push_back
      #define M 1000000007
      int mod(int x){
      return ((x%M + M)%M);
      }
      int add(int a,int b){
      return mod(mod(a)+mod(b));
      }
      int mul(int a,int b){
      return mod(mod(a)*mod(b));
      }
      // ****************************************************************************
      const int maxn = 2e5 + 5;
      int ft[2*maxn],tree[8*maxn],diary[8*maxn],in[maxn],out[maxn],timer;
      vector<int>v[maxn];
      
      void dfs(int src,int par){
      ft[timer] = src;
      in[src] = timer++;
      for(auto &it : v[src]){
      if(it==par)
      continue;
      dfs(it,src);
      }
      ft[timer] = src;
      out[src] = timer++;
      }
      void build(int treeind,int tl,int tr){
      if(tl>tr)
      return;
      if(tl==tr){
      tree[treeind] =1ll;
      return;
      }
      int mid = (tl + tr)/2;
      build(2*treeind+1,tl,mid);
      build(2*treeind+2,mid+1,tr);
      tree[treeind] = tree[2*treeind+1] + tree[2*treeind+2];
      }
      void prop(int treeind,int tl,int tr){
      if(diary[treeind]){
      int val = tree[treeind];
      tree[treeind] = (tr-tl+1) - val;
      if(tl!=tr){
      diary[2*treeind+1]^=1ll;
      diary[2*treeind+2]^=1ll;
      }
      diary[treeind] = 0;
      }
      }
      int l,r;
      void upd(int treeind,int tl,int tr){
      if(tl>tr)
      return;
      prop(treeind,tl,tr);
      if(tl>r || tr<l)
      return;
      if(tl>=l && tr<=r){
      int val = tree[treeind];
      tree[treeind] = (tr-tl+1) - val;
      if(tl!=tr){
      diary[2*treeind+1]^=1ll;
      diary[2*treeind+2]^=1ll;
      }
      return;
      }
      int mid = (tl + tr)/2;
      upd(2*treeind+1,tl,mid);
      upd(2*treeind+2,mid+1,tr);
      tree[treeind] = tree[2*treeind+1] + tree[2*treeind+2];
      }
      int qry(int treeind,int tl,int tr){
      if(tl>tr)
      return 0ll;
      prop(treeind,tl,tr);
      if(tl>r || tr<l)
      return 0ll;
      if(tl>=l && tr<=r)
      return tree[treeind];
      int mid = (tl + tr)/2;
      return qry(2*treeind+1,tl,mid) + qry(2*treeind+2,mid+1,tr);
      }
      
      void solve(){
      int n;
      cin>>n;
      fo(i,0,n-1){
      int a,b;
      cin>>a>>b;
      v[a].pb(b);
      v[b].pb(a);
      }
      dfs(1,0);
      build(0,0,2*n-1);
      int q;
      cin>>q;
      while(q--){
      int ty;
      cin>>ty;
      if(ty==1){
      int u,v;
      cin>>u>>v;
      int par,ch;
      if(in[u]>=in[v] && out[u]<=out[v]){
      par=v,ch=u;
      }
      else{
      par=u,ch=v;
      }
      l = in[ch];
      r = out[ch];
      int tot = tree[0]/2;
      int ans = qry(0,0,2*n-1);
      ans/=2;
      cout<<(tot-ans)*ans<<"\n";
      }
      else{
      int node;
      cin>>node;
      l = in[node];
      r = out[node];
      upd(0,0,2*n-1);
      }
      }
      }
      signed main()
      {
      FIO
      int t;
      t=1;
      // cin>>t;
      while(t--)
      {
      solve();
      }
      }
      See less
        • 0
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    2. Asked: January 5, 2022In: Programming Language

      The Rumbling is a hypothetical cataclysmic event involving Karl Fritz’s Wall Titans marching across the Earth, destroying all life upon …

      I'M ADMIN
      I'M ADMIN
      Added an answer on January 5, 2022 at 8:33 pm

      #include <bits/stdc++.h> #define int long long int #define endl '\n' using namespace std; signed  main() {          int t;cin>>t;     while(t--)     {         int n,x,y,i;cin>>n;         string s;         cin>>s;         cin>>x>>y;         int a[n+1],b[n+1];      Read more

      #include <bits/stdc++.h>
      
      #define int long long int
      
      #define endl '\n'
      
      using namespace std;
      
      signed  main()
      
      {
      
          
      
          int t;cin>>t;
      
          while(t--)
      
          {
      
              int n,x,y,i;cin>>n;
      
              string s;
      
              cin>>s;
      
              cin>>x>>y;
      
              int a[n+1],b[n+1];
      
              a[0]=0;b[0]=0;
      
              for(i=0;i<n;i++)
      
              {
      
                  if(s[i]=='E')
      
                  {
      
                      a[i+1]=a[i]+0;
      
                  }
      
                  else if(s[i]=='W')
      
                  {
      
                      a[i+1]=min(2ll*x,2ll*y)+a[i];
      
                  }
      
                  else if(s[i]=='N')
      
                  {
      
                      a[i+1]=min(x,3ll*y)+a[i];
      
                  }
      
                  else if(s[i]=='S')
      
                  {
      
                       a[i+1]=min(y,3ll*x)+a[i];
      
                  }
      
              }
      
              for(i=0;i<n;i++)
      
              {
      
                  if(s[i]=='E')
      
                  {
      
                      b[i+1]=b[i]+min(2ll*x,2ll*y);
      
                  }
      
                  else if(s[i]=='W')
      
                  {
      
                      b[i+1]=0+b[i];
      
                  }
      
                  else if(s[i]=='N')
      
                  {
      
                      b[i+1]=min(y,3ll*x)+b[i];
      
                  }
      
                  else if(s[i]=='S')
      
                  {
      
                       b[i+1]=min(x,3ll*y)+b[i];
      
                  }
      
              }
      
              int ans=min(a[n],b[n]),z;
      
              for(i=1;i<n;i++)
      
              {
      
                  z= a[i]+b[n]-b[i];
      
                  ans=min(ans,z);
      
              }
      
              cout<<ans<<endl;
      
          }
      
          return 0;
      
      }
      See less
        • 0
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    3. Asked: January 5, 2022In: Programming Language

      The Rumbling is a hypothetical cataclysmic event involving Karl Fritz’s Wall Titans marching across the Earth, destroying all life upon …

      I'M ADMIN
      I'M ADMIN
      Added an answer on January 5, 2022 at 8:33 pm

      #include <bits/stdc++.h> #define int long long int #define endl '\n' using namespace std; signed main() { int t;cin>>t; while(t--) { int n,x,y,i;cin>>n; string s; cin>>s; cin>>x>>y; int a[n+1],b[n+1]; a[0]=0;b[0]=0; for(i=0;i<n;i++) { if(s[i]=='E') { a[i+1]=a[iRead more

      #include <bits/stdc++.h>
      #define int long long int
      #define endl '\n'
      using namespace std;
      signed main()
      {
      
      int t;cin>>t;
      while(t--)
      {
      int n,x,y,i;cin>>n;
      string s;
      cin>>s;
      cin>>x>>y;
      int a[n+1],b[n+1];
      a[0]=0;b[0]=0;
      for(i=0;i<n;i++)
      {
      if(s[i]=='E')
      {
      a[i+1]=a[i]+0;
      }
      else if(s[i]=='W')
      {
      a[i+1]=min(2ll*x,2ll*y)+a[i];
      }
      else if(s[i]=='N')
      {
      a[i+1]=min(x,3ll*y)+a[i];
      }
      else if(s[i]=='S')
      {
      a[i+1]=min(y,3ll*x)+a[i];
      }
      }
      for(i=0;i<n;i++)
      {
      if(s[i]=='E')
      {
      b[i+1]=b[i]+min(2ll*x,2ll*y);
      }
      else if(s[i]=='W')
      {
      b[i+1]=0+b[i];
      }
      else if(s[i]=='N')
      {
      b[i+1]=min(y,3ll*x)+b[i];
      }
      else if(s[i]=='S')
      {
      b[i+1]=min(x,3ll*y)+b[i];
      }
      }
      int ans=min(a[n],b[n]),z;
      for(i=1;i<n;i++)
      {
      z= a[i]+b[n]-b[i];
      ans=min(ans,z);
      }
      cout<<ans<<endl;
      }
      return 0;
      }
      See less
        • 1
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    4. Asked: January 5, 2022In: Programming Language

      You’re given two integers NN and MM. Find if there exists a number which is multiple of one and divisor of the other.

      I'M ADMIN
      I'M ADMIN
      Added an answer on January 5, 2022 at 8:31 pm

      #include <iostream> using namespace std; int main() { int t; cin>>t; while(t--){ int n,m; cin>>n>>m; if(m%n==0){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } } return 0; }

      #include <iostream>
      using namespace std;
      
      int main() {
      
      int t;
      cin>>t;
      while(t--){
      int n,m;
      cin>>n>>m;
      if(m%n==0){
      cout<<"Yes"<<endl;
      }
      else{
      cout<<"No"<<endl;
      }
      }
      return 0;
      }
      See less
        • 1
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    5. Asked: January 5, 2022In: Data Structure

      Implement a C++ program to store Strings in Binary Search tree. Your program should have following functions: Insert Display Search …

      I'M ADMIN
      I'M ADMIN
      Added an answer on January 5, 2022 at 11:51 am

      Steps:   Create a Node structure that has a left and right pointer to point to the left and right child nodes. Create a BST using recursion. While insertion the value is checked with the root value. If the value is lesser than the root we move to the left subtree else to the right subtree. This contRead more

      Steps:

       

      Create a Node structure that has a left and right pointer to point to the left and right child nodes.

      Create a BST using recursion. While insertion the value is checked with the root value. If the value is lesser than the root we move to the left subtree else to the right subtree. This continues until an empty place is found to place the new node.

      The display function displays the nodes of the tree in an inorder fashion this is left root right.

      The search function returns NULL if no such target is found else returns the node with the target value.

      #include<iostream>
      
      using namespace std;
      
      struct Node{
      string val;
      struct Node *left;
      struct Node *right;
      };
      
      //method to insert new nodes
      struct Node* insertNode(struct Node *root,string val)
      {
      if(root==NULL)
      {
      //create a new node
      struct Node *newNode=new Node();
      newNode->val=val;
      newNode->left=newNode->right=NULL;
      return newNode;
      }
      
      if(val<root->val)
      root->left=insertNode(root->left,val);
      else
      root->right=insertNode(root->right,val);
      
      return root;
      }
      
      //method to display the tree
      void display(struct Node *root)
      {
      //perform inorder traversal
      if(root!=NULL)
      {
      display(root->left);
      cout<<root->val<<" ";
      display(root->right);
      }
      }
      
      //method to search the tree
      struct Node* searchNode(struct Node *root,string val)
      {
      if(root==NULL || root->val==val)
      {
      return root;
      }
      if(root->val<val)
      {
      return searchNode(root->right,val);
      }
      return searchNode(root->left,val);
      }
      
      int main()
      {
      struct Node *root=NULL,*node;
      
      //display the menu
      int choice;
      string val;
      
      while(1)
      {
      cout<<"1. Insert Node"<<endl;
      cout<<"2. Display Nodes"<<endl;
      cout<<"3. Search Node"<<endl;
      cout<<"4. Exit"<<endl;
      cout<<"Enter choice: ";
      cin>>choice;
      
      fflush(stdin);
      switch(choice)
      {
      case 1: cout<<"Enter string: ";
      getline(cin,val);
      root=insertNode(root,val);
      cout<<val<<" added"<<endl;
      break;
      case 2: cout<<"Inorder traversal of tree: ";
      display(root);
      cout<<endl;
      break;
      case 3: cout<<"Enter string: ";
      getline(cin,val);
      node=searchNode(root,val);
      if(node==NULL)
      {
      cout<<val<<" not found."<<endl;
      }
      else{
      cout<<val<<" found."<<endl;
      }
      break;
      case 4: exit(0);
      default:cout<<"Wrong choice"<<endl;
      }
      cout<<endl;
      }
      }
      See less
        • 0
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    6. Asked: December 30, 2021In: Other

      EEE full form in engineering ? EEE stand for ___ in engineering.

      I'M ADMIN
      I'M ADMIN
      Added an answer on December 30, 2021 at 9:22 pm

      EEE is a very important subject that is related to engineering. The full meaning of EEE is Electrical and Electronics Engineering. This is probably the most disciplined field in the field of engineering; thus pursuing EEE can be a little challenging. As the full form states, the interested candidateRead more

      EEE is a very important subject that is related to engineering.
      The full meaning of EEE is Electrical and Electronics Engineering.
      This is probably the most disciplined field in the field of engineering; thus pursuing
      EEE can be a little challenging.
      As the full form states, the interested candidate will have to deal with electrical and electronics engineering.

      See less
        • 1
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    1 … 92 93 94 95 96 … 122

    Sidebar

    store ads

    Stats

    • Questions 1k
    • Answers 1k
    • Posts 149
    • Best Answers 89
    • This Free AI Tool Translates Entire Books in Minute !
    • AI News: 🎬 Hollywood’s AI Studios, 🎓 OpenAI’s Latest Gift to Educators, 🚚 Class8 Bags $22M, 🧠 Google Gemini’s Memory Upgrade
    • AI NEWS: Legal Action Against OpenAI, $16M Paid, & Elon Musk’s Praise from Investor 🤖💰📑 | AI Boosts Cloud Seeding for Water Security 🌱💧
    • AI News: 🎬AI Video Tool Scam Exposed🤯, 🛰️ AI-Powered Drones to Ukraine 😱, Google’s $20M AI Push, Sam Altman Joins SF’s Leadership Team
    • AI News: 🤝 Biden Meets Xi on AI Talks, 💡 Xavier Niel’s Advice for Europe, ♻️ Hong Kong’s Smart Bin Revolution, 🚀 AI x Huawei

    Explore

    • Recent Questions
    • Questions For You
    • Answers With Time
    • Most Visited
    • New Questions
    • Recent Questions With Time

    Footer

    SIKSHAPATH

    Helpful Links

    • Contact
    • Disclaimer
    • Privacy Policy Notice
    • TERMS OF USE
    • FAQs
    • Refund/Cancellation Policy
    • Delivery Policy for Sikshapath

    Follow Us

    © 2021-24 Sikshapath. All Rights Reserved