A system of linear equations is a collection of linear equations involving the same set of variables. A general system of linear equations with unknowns can be written as:
Here, are the unknowns, are the coefficients of the system, and are the constant terms. (Source: Wikipedia)
Write a program that solves a system of linear equations with a maximum of equations and variables.
Input Specification
Line of the input contains integers and , indicating the number of variables to solve for and the number of equations in the system.
The next lines will each contain integers, where the first integers are the coefficients of the equation and the last integer is the constant term.
Every number in the input is guaranteed to have absolute value at most .
It is guaranteed that the input is generated randomly. Specifically, for each test case, and will be picked arbitrarily, and so will two other integers, and . Then, all other values in the input will be integers picked uniformly at random between and .
Output Specification
If the system can be solved, output lines, the values of the unknowns .
Your solution will be considered correct if each value has at most absolute or relative error.
If there are no solutions to the system, or if there are infinite solutions to the system, output NO UNIQUE SOLUTION
.
Sample Input 1
2 2
1 3 4
2 3 6
Sample Output 1
2
0.66667
Explanation for Sample Output 1
This asks for the solution(s) for in the system:
Solving for in the first equation gives . Substituting this
into the -nd equation and simplifying yields .
Solving for yields . Substituting back into the
first equation and solving for yields .
Therefore the solution set is the single point .
Sample Input 2
2 3
6 2 2
12 4 8
6 2 4
Sample Output 2
NO UNIQUE SOLUTION
Explanation for Sample Output 2
All of the lines are parallel. Therefore, the system of equations cannot be solved.
Comments
Added the guarantee that the input will be random since the problem would be much harder than intended otherwise. Also updated the data to meet the new constraints and rejudged all submissions.