We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Interview Preparation Kits
  3. 3 Months Preparation Kit
  4. Week 13
  5. Journey to the Moon

Journey to the Moon

Problem
Submissions
Leaderboard
Discussions
Editorial
HackerRank Logo
|
  1. Prepare
  2. Interview Preparation Kits
  3. 3 Months Preparation Kit
  4. Week 13
  5. Journey to the Moon
Exit Full Screen View
  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial

The member states of the UN are planning to send people to the moon. They want them to be from different countries. You will be given a list of pairs of astronaut ID's. Each pair is made of astronauts from the same country. Determine how many pairs of astronauts from different countries they can choose from.

Example


There are astronauts numbered through . Astronauts grouped by country are and . There are pairs to choose from: and .

Function Description

Complete the journeyToMoon function in the editor below.

journeyToMoon has the following parameter(s):

  • int n: the number of astronauts
  • int astronaut[p][2]: each element is a element array that represents the ID's of two astronauts from the same country

Returns
- int: the number of valid pairs

Input Format

The first line contains two integers and , the number of astronauts and the number of pairs.
Each of the next lines contains space-separated integers denoting astronaut ID's of two who share the same nationality.

Constraints

Sample Input

5 3
0 1
2 3
0 4

Sample Output

6

Explanation

Persons numbered , and belong to the same country, and those numbered and belong to the same country, but different from the previous one. All in all, the UN has ways of choosing a pair:

  1. persons and
  2. persons and
  3. persons and
  4. persons and
  5. persons and
  6. persons and
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website