Making friends
Practice
1.8 (25 votes)
Graphs
Algorithms
Graph representation
Problem
43% Success 6536 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code

You opened a school with N students. Each student will either belong to Team Red or Team Blue. The students in each team are friends with each other. However, you want them to make friends with students from the opposite team too. For example, if a student belongs to Team Red, you want that student to make friends with students from Team Blue.

Note: Friendship is mutual. If A is B's friend, then B is automatically A's friend. 

You give each student a number M that represents the number of friends that the student should have from the opposite team.

Your task is to determine whether it is possible for each student to have the number of friends represented by the number M.

Input format

  • The first line of input is a number T denoting the number of test cases.
  • In each test case:
    • The first line contains a positive integer N denoting the number of students.
    • The second line contains an integer M denoting the number of friends that the student should have from the opposite team.

Output format

Print "Yes" or "No" in a new line for each test case based on the possibility that a student can have the number of friends represented by the number M.

Constraints

1<= T <=2*10^5

1 <= N <= 10^5
0 <= M <= 10^5

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
17 votes
Tags:
AlgorithmsGraphsMedium
Points:30
10 votes
Tags:
Ad-HocAlgorithmsCombinatoricsGraphsMedium普通
Points:30
3 votes
Tags:
AlgorithmsGraphsGraph Representation