Ticker

6/recent/ticker-posts

Header Ads Widget

Responsive Advertisement

Online Communities - Even Groups

    
    In a social network, online communities refer to the group of people with an interest towards the same topic. People connect with each other in a social network. A connection between Person I and Person J is represented as C I J. When two persons belonging to different communities connect, the net effect is merger of both communities which I and J belonged to.

    We are only interested in finding out the communities with the member count being an even number. Your task is to find out those communities.

Input Format:

Input will consist of three parts, viz.

1. The total number of people on the social network (N)
2.Queries 
  • C I J, connect I and J
  • Q 0 0, print the number of communities with even member-count
-1 will represent end of input.

Output Format

    For each query Q, output the number of communities with even member-count

Constraints:

1<=N<=10^6

1<=I, J<=N

Sample Input and Output
    Input
    5
    Q 0 0
    C 1 2
    Q 0 0
    C 2 3
    Q 0 0
    C 4 5
    Q 0 0
    -1
    Output

Note:

Please do not use package and namespace in your code. For object oriented languages your code should be written in one class.
Note:

Participants submitting solutions in C language should not use functions from as these files do not exist in gcc

Post a Comment

0 Comments