Advertisement
Guest User

R1P1 Lant

a guest
Mar 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <algorithm>
  4.  
  5. using namespace std ;
  6.  
  7. ifstream f("lant.in");
  8. ofstream g("lant.out");
  9.  
  10. int a[50][50] ;
  11. int n , m , p , q , r , gata = 0 ;
  12. int P[50] , X[50] ;
  13.  
  14. void citire()
  15. {
  16. f >> n >> m ;
  17. for( int i = 1 ; i <= m ; ++i )
  18. {
  19. int x , y ;
  20. f >> x >> y;
  21. a[x][y] = a[y][x] = 1 ;
  22. }
  23. f >> p >> q >> r ;
  24. }
  25.  
  26. void afis( int k )
  27. {
  28. for ( int i = 1 ; i <= k ; ++i )
  29. g << X[i] << " " ;
  30. g << "\n" ;
  31. gata = 1 ;
  32. }
  33.  
  34. void back( int k )
  35. {
  36. if( gata == 0 )
  37. {
  38. for( int i = 1 ; i <= n ; ++i )
  39. if( !P[i] && a[X[k-1]][i] == 1 && gata == 0 )
  40. {
  41. X[k] = i ;
  42. P[i] = 1 ;
  43. if( i == q )
  44. {
  45. int ok = 1 ;
  46. for ( int j = 2 ; j < k && ok ; ++j )
  47. if ( X[j] == r )
  48. ok = 0 ;
  49. if ( !ok )
  50. afis ( k ) ;
  51. }
  52. else
  53. back ( k + 1 ) ;
  54. P[i] = 0 ;
  55. }
  56. }
  57.  
  58. }
  59.  
  60. int main()
  61. {
  62. citire();
  63. //initializam cu p
  64. X[1] = p ;
  65. P[p] = 1 ;
  66. back ( 2 ) ;
  67. f.close();
  68. g.close();
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement