Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- ifstream f("graf.txt");
- int G[10][10],v[10],n,m,l;
- void matrice_adiacenta_vector()
- {
- f>>n>>m;
- int a,b;
- for(int i=1;i<=m;i++)
- {
- f>>a>>b;
- G[a][b]=1;
- }
- f>>l;
- for(int i=1;i<=l;i++)
- f>>v[i];
- }
- void afisare_matrice()
- {
- for(int i=1;i<=n;i++)
- {
- cout<<endl;
- for(int j=1;j<=n;j++)
- cout<<G[i][j]<<" ";
- }
- }
- int verf_drum()
- {
- int OK=1;
- for(int i=1;i<l;i++)
- if(G[v[i]][v[i+1]] == 0)
- OK=0;
- if(OK == 1)
- {
- cout<<endl<<"vectorul este drum";
- return 1;
- }
- else
- {
- cout<<endl<<"nu este drum";
- return 0;
- }
- }
- int elementar()
- {
- int OK=1;
- for(int i=1;i<l;i++)
- for(int j=i+1;j<=l;j++)
- if(v[i]==v[j])
- return 0;
- return 1;
- }
- int simplu()
- {
- int OK=1;
- for(int i=1;i<n;i++)
- for(int j=i+1;j<n;j++)
- if(G[v[i]][v[i+1]] == G[v[j]][v[j+1]])
- OK=0;
- if(OK = 1)
- return 1;
- else
- return 0;
- }
- int main()
- {
- matrice_adiacenta_vector();
- afisare_matrice();
- verf_drum();
- if(verf_drum)
- {
- if(elementar())
- cout<<endl<<"e drum elementar";
- else
- cout<<endl<<"nu e drum elementar";
- if(simplu())
- cout<<endl<<"e drum simplu";
- else
- cout<<endl<<"nu e drum simplu";
- if(v[1] == v[l])
- {
- cout<<endl<<"drumul este circuit";
- if(elementar)
- cout<<endl<<"e circuit elementar";
- else
- cout<<endl<<"nu e circuit elementar";
- }
- else
- cout<<endl<<"drumul nu e circuit";
- }
- if(elementar())
- cout<<endl<<"drumul este hamiltonian";
- else
- cout<<endl<<"drumul nu este hamiltonian";
- if(simplu())
- cout<<endl<<"drumul este eulerian";
- else
- cout<<endl<<"drumul nu este eulerian";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement