Recently, lzd has been learning two-view correspondences and geometry using order-aware network, which is a neural network that infers the probabilities of correspondences being inliers and regresses the relative pose encoded by the essential matrix. The order-aware network contains three novel operations: differentiable pooling layer(a permutation-invariant methods to cluster nodes in a learnable manner and capture the local context), order-aware differentiable unpooling layer(to upsample the coarsened feature maps and build a hierarchical architecture), and order-aware filtering block(to capture the global context with spatial connections). Since the order-aware network achieved the state-of-the-art(SOTA) performance, lzd considers it a good methods and want to share a problem, which is relevant to one of the operation mentioned above, for you to solve.
Shortly, the problem can be refined as:
You are given a matrix A with the shape of n×m and a matrix B with the shape of m×m. You can swap the arbitrary(任意) two rows of A and you can do this operation arbitrary times(possibly, 0 times).
Now, the question is that is it possible to make B=AT×A, where the AT stands for the transpose(转置) of matrix A and the "××" stands for the multiplication between two matrix.
Input
The first line consists of two integers n,m(1≤n,m≤100), describing the shape of A and B.
In the following n lines, each line contains m intergers Ai,j(0≤Ai,j≤106), denoting the matrix A.
In the following m lines, each line contains m intergers Bi,j(0≤Bi,j≤1015), denoting the matrix B
Output
Output a line containing a string. Output "YES"(without quotes) or "NO"(without quotes), denonting is it possible for you to make B=AT×A.
Sample 1
Inputcopy Outputcopy 6 6 1 1 4 5 1 4 1 1 4 5 1 4 1 1 4 5 1 4 1 1 4 5 1 4 1 1 4 5 1 4 1 1 4 5 1 4 6 6 24 30 6 24 6 6 24 30 6 24 24 24 96 120 24 96 30 30 120 150 30 120 6 6 24 30 6 24 24 24 96 120 24 96 YESSample 2
Inputcopy Outputcopy 1 4 1 2 3 4 1 2 3 114514 2 4 6 8 3 6 9 12 4 8 12 16
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;
#define int long long
typedef pair<int,int>PII;
constexpr int N=105;
int a[N][N];
int b[N][N];
signed main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
bool st=false;
for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++){
cin>>b[i][j];
for(int k=1;k<=n;k++){
b[i][j]-=a[k][i]*a[k][j];
}
if(b[i][j]) st= true;
}
}
if(st) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return 0;
}