Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream fin("graf.in");
- ofstream fout("graf.out");
- int a[20][20],n,m,v[25],nr;
- void Matrice()
- {
- int i,j,k;
- fin>>n>>m;
- for(k=1;k<=m;k++)
- {
- fin>>i>>j;
- a[i][j]=a[j][i]=1;
- }
- fin>>nr;
- for(i=1;i<=nr;i++)
- {
- fin>>v[i];
- }
- fin.close();
- }
- void Afisare()
- {
- int i=1,j=1;
- for(i=1;i<=n;i++)
- {
- for(j=1;j<=n;j++)
- fout<<a[i][j]<<" ";
- fout<<"\n";
- }
- }
- int Lant()
- {
- int i,j;
- for(i=1;i<nr;i++)
- {
- if(a[v[i]][v[i+1]]==0)
- return 0;
- }
- //Daca este lant verific daca este lementar sau nu
- for(i=1;i<nr;i++)
- for(j=i+1;j<=nr;j++)
- {
- if(v[i]==v[j])
- return 2;
- }
- return 1;
- }
- int main()
- {
- int i;
- Matrice();
- fout<<"Matricea contine:\n";
- Afisare();
- if(Lant()==1)
- fout<<"\nLant elementar";
- else
- if(Lant()==2)
- fout<<"\nLant neelementar";
- else
- fout<<"\nNu este lant";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement