Advertisement
frentzy

Untitled

Apr 26th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. ifstream fin("graf.in");
  6. ofstream fout("graf.out");
  7. int a[20][20],n,m,v[25],nr;
  8. void Matrice()
  9. {
  10. int i,j,k;
  11. fin>>n>>m;
  12. for(k=1;k<=m;k++)
  13. {
  14. fin>>i>>j;
  15. a[i][j]=a[j][i]=1;
  16. }
  17. fin>>nr;
  18. for(i=1;i<=nr;i++)
  19. {
  20. fin>>v[i];
  21. }
  22. fin.close();
  23. }
  24.  
  25. void Afisare()
  26. {
  27. int i=1,j=1;
  28. for(i=1;i<=n;i++)
  29. {
  30. for(j=1;j<=n;j++)
  31. fout<<a[i][j]<<" ";
  32. fout<<"\n";
  33. }
  34. }
  35.  
  36. int Lant()
  37. {
  38. int i,j;
  39. for(i=1;i<nr;i++)
  40. {
  41. if(a[v[i]][v[i+1]]==0)
  42. return 0;
  43. }
  44. //Daca este lant verific daca este lementar sau nu
  45. for(i=1;i<nr;i++)
  46. for(j=i+1;j<=nr;j++)
  47. {
  48. if(v[i]==v[j])
  49. return 2;
  50. }
  51. return 1;
  52. }
  53.  
  54.  
  55.  
  56. int main()
  57. {
  58. int i;
  59. Matrice();
  60. fout<<"Matricea contine:\n";
  61. Afisare();
  62. if(Lant()==1)
  63. fout<<"\nLant elementar";
  64. else
  65. if(Lant()==2)
  66. fout<<"\nLant neelementar";
  67. else
  68. fout<<"\nNu este lant";
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement