a53

Gasti

a53
Dec 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #include <fstream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. #define Nmax 100002
  7. #define Mod 666013
  8.  
  9. ifstream fin ( "gasti.in" );
  10. ofstream fout ( "gasti.out" );
  11.  
  12. vector < int > G[Nmax];
  13. int Gasca[Nmax], Members[Nmax], Cate[Nmax];
  14.  
  15. int cnt = 0;
  16. void DFS ( int node, int gasca ){
  17.  
  18. cnt++;
  19. Gasca[node] = gasca;
  20.  
  21. vector < int > :: iterator it;
  22. for ( it = G[node].begin(); it != G[node].end(); ++it ){
  23. if ( !Gasca[*it] )
  24. DFS ( *it, gasca );
  25. }
  26. }
  27.  
  28. int main(){
  29.  
  30. int N, M;
  31.  
  32. fin >> N >> M;
  33. for ( int i = 1; i <= M; ++i ){
  34. int x, y;
  35. fin >> x >> y;
  36. G[x].push_back ( y );
  37. G[y].push_back ( x );
  38. }
  39.  
  40. int gasti = 0, max1 = -1, max2 = -1;
  41. for ( int i = 1; i <= N; ++i ){
  42. if ( !Gasca[i] ){
  43. cnt = 0;
  44. DFS ( i, ++gasti );
  45. Members[gasti] = cnt;
  46. Cate[Members[gasti]]++;
  47.  
  48. if ( Members[gasti] > max1 ){
  49. max2 = max1;
  50. max1 = Members[gasti];
  51. }
  52. else if ( Members[gasti] > max2 )
  53. max2 = Members[gasti];
  54. }
  55. }
  56.  
  57. long long x, y;
  58. if ( max1 != max2 ){
  59. x = ( 1LL * Cate[max1] * max1 ) % Mod;
  60. y = ( 1LL * Cate[max2] * max2 ) % Mod;
  61. }
  62. else{
  63. x = ( 1LL * max1 * max1 ) % Mod;
  64. y = ( 1LL * Cate[max1] * ( Cate[max1]-1 ) / 2 ) % Mod;
  65. }
  66. long long rez = ( x * y ) % Mod;
  67.  
  68. fout << gasti << " " << rez;
  69.  
  70. return 0;
  71. }
Add Comment
Please, Sign In to add comment