You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A matrix B (consisting of integers) of dimension N × N is said to be good if there exists an array A (consisting of integers) such that B[i][j] = |A[i] - A[j]|, where |x| denotes absolute value of integer x.
4
+
5
+
You are given a partially filled matrix B of dimension N × N. Q of the entries of this matrix are filled by either 0 or 1. You have to identify whether it is possible to fill the remaining entries of matrix B (the entries can be filled by any integer, not necessarily by 0 or 1) such that the resulting fully filled matrix B is good.
6
+
Input
7
+
The first line of the input contains an integer T denoting the number of test cases.
8
+
9
+
The first line of each test case contains two space separated integers N, Q.
10
+
11
+
Each of the next Q lines contain three space separated integers i, j, val, which means that B[i][j] is filled with value val.
12
+
Output
13
+
For each test case, output "yes" or "no" (without quotes) in a single line corresponding to the answer of the problem.
14
+
Constraints
15
+
1 ≤ T ≤ 10^6
16
+
2 ≤ N ≤ 10^5
17
+
1 ≤ Q ≤ 10^6
18
+
1 ≤ i, j ≤ N
19
+
0 ≤ val ≤ 1
20
+
Sum of each of N, Q over all test cases doesn't exceed 106
0 commit comments