fork download
  1. #include <stdio.h>
  2. #include<vector>
  3. using namespace std;
  4. vector<int>v[100005];//but why do you create the array size here?array size is not needed-isnt that the main advantage of vector?or is it a 2d array??
  5. int length;
  6. bool vis[100005];//is bool another datatype?
  7. void dfs(int i)
  8. {
  9. for(int j=0;j<v[i].size();j++)//v[i].size() means??size() is a function??
  10. {
  11. if(!vis[v[i][j]])
  12. {
  13. length++;
  14. vis[v[i][j]]=1;
  15. dfs(v[i][j]);
  16. }
  17. }
  18. }
  19. int main()
  20. {
  21. int t;
  22. scanf("%d",&t);
  23. while(t--)
  24. {
  25. int x,y,n,q,count=0;
  26. scanf("%d%d",&n,&q);
  27. while(q--)
  28. {
  29. scanf("%d%d",&x,&y);
  30. v[x-1].push_back(y-1);
  31. v[y-1].push_back(x-1);
  32. }
  33. long long unsigned sum=1;
  34. for(int i=0;i<n;i++)
  35. {
  36. if(!vis[i])
  37. {
  38. vis[i]=1;
  39. count++;
  40. length=1;
  41. for(int j=0;j<v[i].size();j++)
  42. {
  43. if(!vis[v[i][j]])
  44. {
  45. vis[v[i][j]]=1;
  46. dfs(v[i][j]);
  47. length++;
  48. }
  49. }
  50. sum*=length;
  51. sum%=1000000007;
  52. }
  53. }
  54. printf("%d %llu\n",count,sum);
  55. for(int i=0;i<n;vis[i++]=0)
  56. v[i].clear();
  57. }
  58. return 0;
  59. }
Runtime error #stdin #stdout 0s 4120KB
stdin
Standard input is empty
stdout
Standard output is empty