Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Template
- //Includes
- #include<iostream>
- #include <vector>
- #include <queue>
- #include <map>
- #include <set>
- #include <utility> //Pair
- #include <algorithm>
- #include <sstream> // istringstream>> ostring stream<<
- #include <iostream>
- #include <iomanip>
- #include <cstdio>
- #include <cmath>
- #include <cstdlib>
- #include <ctime>
- #include <cstring>
- using namespace std;
- typedef long long ll;
- typedef pair<int,int> ii;
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef vector<ii> vii;
- typedef vector<vii> vvii;
- #define pb push_back
- #define mp make_pair
- #define ff first
- #define ss second
- #define rep(i,c,n) for(int i=c;i<n;i++)
- #define MOD 747474747
- int main()
- {int T,N,D;
- scanf("%d",&T);
- while(T--)
- {scanf("%d%d",&N,&D);
- vector< vector<ll> >g(N,vector<ll>(N));//g[i][j] stores the distance between points i,j or the adjacency matrix
- vb disc(N,0);//discovery vector.initialised to undiscovered
- ll points[N][D];//points are stored in array
- ll ans=1;
- //graph input taken
- rep(i,0,N)//for the n points
- rep(j,0,D)//for each dimension
- scanf("%lld",&points[i][j]);
- //calculate the distance b/w every point
- rep(i,0,N)
- {rep(j,i,N)
- {ll dist=0;
- rep(k,0,D)
- dist+=(points[i][k]-points[j][k])*(points[i][k]-points[j][k]);
- g[i][j]=g[j][i]=dist;
- }
- }//distance has been calculated
- //Prim O(V^2).
- int s=0;//start point.This is the point that moves through the graph
- disc[s]=1;
- rep(i,0,N-1)//iterating n-1 times since evry time we include a new vertex in MAXST
- {ll max=0;
- int v;
- rep(j,0,N)//through the adj(s)
- {if(!disc[j]&&g[s][j]==0)//this means that the point j and s are the same points
- disc[j]=1;
- if(!disc[j]&&max<g[s][j])
- {max=g[s][j];
- v=j;}
- }
- if(max==0)
- break;
- ans=(ans*(max%MOD))%MOD;
- s=v;
- disc[s]=1;
- }
- printf("%lld\n",ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement