What is the output of the program

Assignment Help C/C++ Programming
Reference no: EM13803429

What is the output of the given program:

#include <iostream>

#include <algorithm>

using namespace std;

int cnt=0;
int Even=0;
int sz[1000005];
int id[1000005];
void UF(int N)
{
  cnt = N;
  for(int i=0; i<N; i++){
  id[i] = i;
  sz[i] = 1;
}
}

int find(int p) {
int root = p;
while (root != id[root])
root = id[root];
while (p != root) {
int newp = id[p];
id[p] = root;
p = newp;
}
return root;
}
void merge(int x, int y) {
int i = find(x);
int j = find(y);
if (i == j) return;

if (sz[i] < sz[j]){
id[i] = j;
if(sz[i]%2==0)
Even--;
int prev=sz[j];
sz[j] += sz[i];
cout<<"**"<<sz[i]<<" "<<prev<<" "<<sz[j]<<endl;
if(sz[j]%2==0 && prev%2!=0)
Even++;
if(sz[j]%2!=0 && prev%2==0)
Even--;

} else {
id[j] = i;
if(sz[j]%2==0)
Even--;
int prev=sz[i];
sz[i] += sz[j];
cout<<"&&"<<sz[i]<<" "<<prev<<" "<<sz[j]<<endl;
if(sz[i]%2==0 && prev%2!=0)
Even++;
if(sz[i]%2!=0 && prev%2==0)
Even--;
}
cnt--;
}

bool connected(int x, int y){
return find(x) == find(y);
}

int count(){
return cnt;
}
int main()
{
int friends,Conn,A,B;
cin>>Conn;
UF(100005);
char C;
for(int i=0;i<Conn;i++){
cin>>C>>A>>B;
if(C=='C')
merge(A,B);
else
cout<<Even;
cout<<endl;
}
return 0;
}

Reference no: EM13803429

Questions Cloud

How does federal environmental planning influence state : List and discuss the reasons why environmental planning can be difficult to pursue. How does federal environmental planning influence state and local environmental planning
Integrated development environment : Based on Greiner (2008), should C++ programming language be extended to include an XML editor and parser like Java programming language? Or, should this be built into the integrated development environment (IDE) that supports the programming langu..
Write a research paper on the brave tin soldier : Write a research paper on The Brave Tin Soldier.
Supporting and transforming business : Resources Introduction to Information Systems: Supporting and Transforming Business. Read the Case Study, Amazon: From Book Seller to Service Provider.
What is the output of the program : What is the output of the program
Individual assignment rite of passage paper : Individual Assignment Rite of Passage Paper
Are scripting languages such as javascript better choice : Based on Keston (2008), does the C++ programming language have a role in developing Web 2.0 application solutions based on service-oriented architectures (SOA)? Explain why or why not. Are scripting languages such as JavaScript Perl or Python bett..
Explain public planning and private planning : How does planning theory differ from the practice of planning? What is the major difference between public planning and private planning. List and discuss three theoretical approaches to the process of planning
Ethical perspective has evolved throughout the program : Explain the role of ethics and social responsibility in developing a strategic plan, considering stakeholder needs. Explain how your ethical perspective has evolved throughout the program.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd