Advertisement
jaskaran_1

CHEFGAME

Jun 22nd, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. //Template
  2. //Includes
  3. #include<iostream>
  4. #include <vector>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <utility> //Pair
  9. #include <algorithm>
  10. #include <sstream> // istringstream>> ostring stream<<
  11. #include <iostream>
  12. #include <iomanip>
  13. #include <cstdio>
  14. #include <cmath>
  15. #include <cstdlib>
  16. #include <ctime>
  17. #include <cstring>
  18. using namespace std;
  19.  
  20. typedef long long ll;
  21. typedef pair<int,int> ii;
  22. typedef vector<int> vi;
  23. typedef vector<bool> vb;
  24. typedef vector<ii> vii;
  25. typedef vector<vii> vvii;
  26. #define pb push_back
  27. #define mp make_pair
  28. #define ff first
  29. #define ss second
  30. #define rep(i,c,n) for(int i=c;i<n;i++)
  31. #define MOD 747474747
  32. int main()
  33. {int T,N,D;
  34. scanf("%d",&T);
  35. while(T--)
  36. {scanf("%d%d",&N,&D);
  37.  vector< vector<ll> >g(N,vector<ll>(N));//g[i][j] stores the distance between points i,j or the adjacency matrix
  38.  vb disc(N,0);//discovery vector.initialised to undiscovered
  39.  ll points[N][D];//points are stored in array
  40.  ll ans=1;
  41.  //graph input taken
  42.  rep(i,0,N)//for the n points
  43.  rep(j,0,D)//for each dimension
  44.  scanf("%lld",&points[i][j]);
  45.  //calculate the distance b/w every point
  46.  rep(i,0,N)
  47.  {rep(j,i,N)
  48.  {ll dist=0;
  49.   rep(k,0,D)
  50.   dist+=(points[i][k]-points[j][k])*(points[i][k]-points[j][k]);
  51.   g[i][j]=g[j][i]=dist;
  52.   }
  53.  }//distance has been calculated
  54. //Prim O(V^2).
  55. int s=0;//start point.This is the point that moves through the graph
  56. disc[s]=1;
  57. rep(i,0,N-1)//iterating n-1 times since evry time we include  a new vertex in MAXST
  58. {ll max=0;
  59.  int v;
  60.  rep(j,0,N)//through the adj(s)
  61. {if(!disc[j]&&g[s][j]==0)//this means that the point j and s are the same points
  62.   disc[j]=1;
  63.  if(!disc[j]&&max<g[s][j])
  64.  {max=g[s][j];
  65.   v=j;}
  66.  }
  67.  if(max==0)
  68.  break;
  69. ans=(ans*(max%MOD))%MOD;
  70. s=v;
  71. disc[s]=1;
  72. }
  73. printf("%lld\n",ans);
  74.  }
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement