Perpendicular Lines

3.4

9 votes
Easy, Math
Problem

Given 4 points of the form (xi, yi) in 2D plane, find out if the lines formed by (x1, y1), (x2, y2) and (x3, y3), (x4, y4) are perpendicular to each other.

NOTE:

  • It is NOT provided that the points are distinct i.e the first two or the last two points may be equal too!

INPUT FORMAT:

First line T is the number of test cases. Each test case is followed by 2 lines.

The first line of every test case contains four integers (x1, y1) and (x2, y2).

The second line contains four integers (x3, y3) and (x4, y4).


OUTPUT FORMAT:

For every test case :

  • print "YES" without quotes if the lines are perpendicular to each other
  • print "NO" without quotes if the lines are not perpendicular
  • print "INVALID" without quotes if there are less than 2 lines

CONSTRAINTS:

1 <= T <= 10^5

-10^18 <= xi <= 10^18

-10^18 <= yi <= 10^18

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

First Test case ->

Slope of first line = 0.5

Slope of Second line = -2

Produce of Slopes = -1

Hence they are perpendicular! Answer is "YES".

Second Test Case ->

The Second line is not formed. Hence the answer is "INVALID"

Editor Image

?