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

  C assignment of curl library

C Assignment Curl library must be used To be done on linux, it should be compiled using the following command: gcc -Wall -ansi -pedantic NameOfFile.c -lncurses Please make sure it is commented with clarification Variable names in camel case

  Create a boolean function that computes

Create a Boolean function that computes the value of a factorial for values up to including 10. Include comments about how to use the function and describing how it works.

  Write an interactive program that prompts for a desired sum

Write an interactive program that prompts for a desired sum, then repeatedly rolls two six-sided dice until their sum is the desired sum. Here is the expected dialogue with the user.

  C programme to find the minimum and maximum value

write a c programme to find the minimum and maximum value each elements in each row ,to create table b,having 5 rows and 2 coloums,the first coloum of table b is the maximumvalue and thye second coloum is the maximum value in each row.

  Function odd_fill() that fills all integers between two poin

write a function odd_fill() that fills all integers between two pointers, first and last, with a sequence of odd integers: 1,3,5,7

  Write c program to find smallest-largest values

Write a program c that will find the smallest, largest and average values in a collection of N numbers.Get the value of N before scanning each value in the collection of N numbers.

  Write definitions of the functions to overload the operators

Write the definitions of the functions to overload the operators defined in parts a to c and write  a  test  program  that  tests  various  operations  on  the class rectangleType.

  Use functional decomposition to solve

Use functional decomposition to solve this problem, and code the solution using functions wherever it makes sense to do so. Your program should check for invalid data such as nonpositive dimensions, number of rooms less than 1.

  Write a c++ function that removes and counts all occurrences

Write a C++ function that removes and counts all occurrences of a given string from such a bag. Your function should return this number.

  Prepare a function called perfect

Prepare a function called perfect(NUM) that determines if parameter NUM is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000.

  Heights of the individual pupils

Make a C++ program that helps the health visitor making the statistics and heights of the individual pupils,

  Write a function called distance

Write a function called distance that takes two Points as arguments and returns the distance between them.

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