Advertisement
Guest User

graf elementar

a guest
Mar 25th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int a[100][100],v[100],n;
  5. int k;
  6. void citire_graf(){
  7.     int m,x,y;
  8.     cout<<"nr muchii: ";cin>>m;
  9.     for(int i=1;i<=m;i++){
  10.         cout<<"muchie:";cin>>x>>y;
  11.     a[x][y]=a[y][x]=1;
  12.     }
  13. }
  14. void afisare(int n){
  15. for(int i=1;i<=n;i++)
  16. {for(int j=1;j<=n;j++)
  17.     cout<<a[i][j]<<" ";
  18.     cout<<"\n";
  19. }
  20.  
  21. }
  22.  
  23. void citire_secventa(){
  24.  
  25. cout<<"nr elem: ";cin>>k;
  26. for(int i=1;i<=k;i++)
  27.     cin>>v[i];
  28. }
  29.  
  30. bool eLant(){
  31. for(int i=1;i<k;i++)
  32.     if(a[v[i]][v[i+1]]==0)
  33.         return false;
  34.  
  35. return true;
  36. }
  37. bool elemetrar(){
  38. if(eLant()){
  39. for(int i=1;i<=n;i++)
  40.     for(int j=i+1;j<=n;j++)
  41.         if(v[i]==v[j])
  42.             return false;
  43. return true;
  44. }
  45. return false;
  46. }
  47. int main()
  48. {cout<<"noduri: ";cin>>n;
  49. citire_graf();
  50. afisare(n);
  51. citire_secventa();
  52. if(elemetrar())
  53.     cout<<"da";
  54. else
  55.     cout<<"nu";
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement