Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int x[101],a[101][101],n;
  5. void citire(int &n, int a[101][101])
  6. {
  7. int m,i,j,x,y;
  8. cin>>n;
  9. for(i=1;i<=n;i++)
  10. for(j=1;j<=n;j++)
  11. a[i][j]=0;
  12. cin>>m;
  13. for(i=1;i<=m;i++)
  14. {
  15. cin>>x>>y;
  16. a[x][y]=1;
  17. }
  18. }
  19. void tipar(int k)
  20. {
  21. int i;
  22. for(i=1;i<=k;i++)
  23. {
  24. if(x[i]==1)
  25. cout<<'R';
  26. else
  27. if(x[i]==2)
  28. cout<<'A';
  29. else
  30. cout<<'V';
  31. }
  32. }
  33. int cont(int k)
  34. {
  35. int i,j;
  36. for(i=1;i<k;i++)
  37. for(j=i+1;j<=k;j++)
  38. if(a[i][j]==1 || a[j][i]==1)
  39. {
  40. if(x[i]==x[j])
  41. return 0;
  42. }
  43. return 1;
  44. }
  45. void bkt()
  46. {
  47. int k=1;
  48. x[k]=0;
  49. while(k)
  50. {
  51. if(x[k]<3)
  52. {
  53. x[k]=x[k]+1;
  54. if(cont(k)==1)
  55. {
  56. if(k==n)
  57. {
  58. tipar(k);
  59. break;
  60. }
  61. else
  62. {
  63. k++;
  64. x[k]=0;
  65. }
  66. }
  67. }
  68. else
  69. k--;
  70. }
  71. }
  72. int main()
  73. {
  74. citire(n,a);
  75. bkt();
  76.  
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement