Chef and Balanced Polygons

All submissions for this problem are available.

You are given a convex polygon consisting of n vertices in 2-D plane. You are also given m points, each colored in either red or blue.

A convex polygon is called w00t, if the number of red and blue colored points inside this (inside or on the boundary) are equal.

You want to find number of w00t convex polygons whose vertices are a subset of the vertices of the given convex polygon.

Input

The first line of the input contains an integer T denoting the number of the test cases.

The first line of each test case will contain two space separated integers n, m denoting the number of points on the convex polygon, and number of the colored points, respectively.

In the next n lines, each line contains two space separated integers x, y denoting the x and y coordinates of the points of convex polygon. The points of the convex polygon are given to you in anticlockwise order. It is guaranteed that no three points on the convex polygon are collinear.

In the next m lines, each line contains three space separated integers x, y, c, where x, y denotes the x and y coordinates of the colored points, and c denotes the color of the point. If c = 0, the point is red colored, where if c = 1, point is blue colored..

Output

For each test case, output a single integer corresponding to the number of w00t convex polygons whose vertices are subset of the given convex polygon.

Constraints

1 ≤ T ≤ 20

1 ≤ n, m ≤ 50

n ≥ 3

-106 ≤ |xi, yi| ≤ -106

In the given m points, two or more points might coincide.

Subtasks

Subtask #1: (15 points)

1 ≤ n, m ≤ 12

Subtask #2: (20 points)

Each of the m points has same coordinates as that of some vertices of the convex polygon.

All the colored points have different coordinates.

Subtask #3: (25 points)

Each of the m points has same coordinates as that of some vertices of the convex polygon.

Comments

Please login at the top to post a comment.

SUCCESSFUL SUBMISSIONS

Fetching successful submissions

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.

Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.

Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.

Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.

Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to INR 20,000 (for Indian Community), $700 (for Global Community) and lots more CodeChef goodies up for grabs.