fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int arr[100009],arr1[100009];
  4. int find_grp(int num)
  5. {
  6. while(num!=arr[num])
  7. num=arr[num];
  8. return num;
  9. }
  10. int main()
  11. {
  12. int t;
  13. cin>>t;
  14. while (t--)
  15. {
  16. int n,g;
  17. cin>>n>>g;
  18. int gen[g+1];
  19. for (int i=1; i<=g; i++)
  20. cin>>gen[i];
  21. int q;
  22. cin>>q;
  23. memset(arr,0,sizeof(arr));
  24. memset(arr1,0,sizeof(arr1));
  25. while(q--)
  26. {
  27. int type;
  28. cin>>type;
  29. if (type==1)
  30. {
  31. char c;
  32. cin>>c;
  33. int id1,id2;
  34. cin>>id1>>id2;
  35. if (c=='c')
  36. {
  37. int num=find_grp(id1);
  38. arr[id2]=num;
  39. arr1[id2]=arr[num];
  40. }
  41. if (c=='g'){
  42. arr[id2]=id2;
  43. arr1[id2]=id1;
  44. }
  45. }
  46. if (type==2)
  47. {
  48. int id;
  49. cin>>id;
  50. int num=find_grp(id);
  51. if (num==0)
  52. cout<<"Free\n";
  53. else if (gen[arr1[num]]==0)
  54. cout<<"Bhagat\n";
  55. else
  56. cout<<"Dukkar\n";
  57. }
  58. if (type==3)
  59. {
  60. int id;
  61. cin>>id;
  62. if (gen[id]==0)
  63. gen[id]=1;
  64. else
  65. gen[id]=0;
  66. //gen[id]=!gen[id];
  67. }
  68. }
  69. }
  70. return 0;
  71. }
Success #stdin #stdout 0s 3924KB
stdin
1
3 2
1 0
8
1 g 1 1
1 g 2 2
1 c 2 3
2 1
2 3
3 2
2 3
2 2
stdout
Dukkar
Bhagat
Dukkar
Dukkar