`{"id":"35a28134-f2b3-4880-a6ee-984f16139144","name":"Perfect Friends","description":"1. You are given a number n (representing the number of students). Each student will have an id \r\n from 0 to n - 1.\r\n2. You are given a number k (representing the number of clubs)\r\n3. In the next k lines, two numbers are given separated by a space. The numbers are ids of \r\n students belonging to same club.\r\n4. You have to find in how many ways can we select a pair of students such that both students are \r\n from different clubs.","inputFormat":"Input has been managed for you","outputFormat":"Check the sample output","constraints":"None","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\n\nusing namespace std;\n \nint main(){\n int n;\n cin>>n;\n \n int k;\n cin>>k;\n \n // write your code here\n \n return 0;\n }"},"java":{"code":"import java.io.*;\nimport java.util.*;\n\npublic class Main {\n \n\n public static void main(String[] args) throws Exception {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n int n = Integer.parseInt(br.readLine());\n int k = Integer.parseInt(br.readLine());\n \n // write your code here\n }\n\n}"},"python":{"code":"def main():\n n = int(input())\n k = int(input())\n \n #write your code here\n\nif __name__ == \"__main__\":\n main()"}},"points":10,"difficulty":"easy","sampleInput":"7\r\n5\r\n0 1\r\n2 3\r\n4 5\r\n5 6\r\n4 6","sampleOutput":"16","questionVideo":"https://www.youtube.com/embed/_q4hA01ZcVQ?start=0&end=272","hints":[],"associated":[{"id":"14ce15b7-eebf-4c54-be16-2b8f43788e35","name":"How many connected components of graph are present in following graph? 0 --------1 2-----------4-----------5 6 | | | | | ","slug":"how-many-connected-components-of-graph-are-present-in-following-graph-0-1-2-4-5-6-3-7-8-perfect-friends","type":4},{"id":"3ed1e1c7-ce29-410b-b327-deeb7606db11","name":"What is the time complexity of the solution of \"Perfect Friends\" problem? Here: 'V' represents number of students and 'E' represents number of pairs","slug":"what-is-the-time-complexity-of-the-solution-of-perfect-friends-problem-here-v-represents-number-of-students-and-e-represents-number-of-pairs","type":4},{"id":"531dde3b-a994-43f2-a8b7-fa441439d128","name":"What type of graph is used in \"Perfect Friends\" solution?","slug":"what-type-of-graph-is-used-in-perfect-friends-solution","type":4},{"id":"ebd6530f-ae5d-447c-97b1-44e00b63f5a6","name":"A graph is a collection of.... ? (Perfect Friends)","slug":"a-graph-is-a-collection-of-perfect-friends","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"02ab8fe3-cddd-43ad-b241-b8b1a2fcd52e","name":"Graphs For Beginners","slug":"graphs-for-beginners","type":0},{"id":"e9fc33b4-de9d-416e-b080-1e5a6d895b24","name":"Perfect Friends","slug":"perfect-friends","type":1}],"next":{"id":"c85f9941-f0d3-45db-9158-4e9052bbc859","name":"Perfect Friends","type":3,"slug":"perfect-friends"},"prev":{"id":"32289697-b008-48b4-a28c-e7b4ce4303b2","name":"Number of Islands","type":3,"slug":"number-of-islands"}}}`

# Perfect Friends

1. You are given a number n (representing the number of students). Each student will have an id from 0 to n - 1. 2. You are given a number k (representing the number of clubs) 3. In the next k lines, two numbers are given separated by a space. The numbers are ids of students belonging to same club. 4. You have to find in how many ways can we select a pair of students such that both students are from different clubs.

`{"id":"35a28134-f2b3-4880-a6ee-984f16139144","name":"Perfect Friends","description":"1. You are given a number n (representing the number of students). Each student will have an id \r\n from 0 to n - 1.\r\n2. You are given a number k (representing the number of clubs)\r\n3. In the next k lines, two numbers are given separated by a space. The numbers are ids of \r\n students belonging to same club.\r\n4. You have to find in how many ways can we select a pair of students such that both students are \r\n from different clubs.","inputFormat":"Input has been managed for you","outputFormat":"Check the sample output","constraints":"None","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\n\nusing namespace std;\n \nint main(){\n int n;\n cin>>n;\n \n int k;\n cin>>k;\n \n // write your code here\n \n return 0;\n }"},"java":{"code":"import java.io.*;\nimport java.util.*;\n\npublic class Main {\n \n\n public static void main(String[] args) throws Exception {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n int n = Integer.parseInt(br.readLine());\n int k = Integer.parseInt(br.readLine());\n \n // write your code here\n }\n\n}"},"python":{"code":"def main():\n n = int(input())\n k = int(input())\n \n #write your code here\n\nif __name__ == \"__main__\":\n main()"}},"points":10,"difficulty":"easy","sampleInput":"7\r\n5\r\n0 1\r\n2 3\r\n4 5\r\n5 6\r\n4 6","sampleOutput":"16","questionVideo":"https://www.youtube.com/embed/_q4hA01ZcVQ?start=0&end=272","hints":[],"associated":[{"id":"14ce15b7-eebf-4c54-be16-2b8f43788e35","name":"How many connected components of graph are present in following graph? 0 --------1 2-----------4-----------5 6 | | | | | ","slug":"how-many-connected-components-of-graph-are-present-in-following-graph-0-1-2-4-5-6-3-7-8-perfect-friends","type":4},{"id":"3ed1e1c7-ce29-410b-b327-deeb7606db11","name":"What is the time complexity of the solution of \"Perfect Friends\" problem? Here: 'V' represents number of students and 'E' represents number of pairs","slug":"what-is-the-time-complexity-of-the-solution-of-perfect-friends-problem-here-v-represents-number-of-students-and-e-represents-number-of-pairs","type":4},{"id":"531dde3b-a994-43f2-a8b7-fa441439d128","name":"What type of graph is used in \"Perfect Friends\" solution?","slug":"what-type-of-graph-is-used-in-perfect-friends-solution","type":4},{"id":"ebd6530f-ae5d-447c-97b1-44e00b63f5a6","name":"A graph is a collection of.... ? (Perfect Friends)","slug":"a-graph-is-a-collection-of-perfect-friends","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"02ab8fe3-cddd-43ad-b241-b8b1a2fcd52e","name":"Graphs For Beginners","slug":"graphs-for-beginners","type":0},{"id":"e9fc33b4-de9d-416e-b080-1e5a6d895b24","name":"Perfect Friends","slug":"perfect-friends","type":1}],"next":{"id":"c85f9941-f0d3-45db-9158-4e9052bbc859","name":"Perfect Friends","type":3,"slug":"perfect-friends"},"prev":{"id":"32289697-b008-48b4-a28c-e7b4ce4303b2","name":"Number of Islands","type":3,"slug":"number-of-islands"}}}`

Editor

# Perfect Friends

easy

1. You are given a number n (representing the number of students). Each student will have an id from 0 to n - 1. 2. You are given a number k (representing the number of clubs) 3. In the next k lines, two numbers are given separated by a space. The numbers are ids of students belonging to same club. 4. You have to find in how many ways can we select a pair of students such that both students are from different clubs.

None

## Format

### Input

Input has been managed for you

### Output

Check the sample output

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}7 5 0 1 2 3 4 5 5 6 4 6```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}16`

Question Video

Discussions

Show Discussion

Related Resources