Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- using namespace std;
- int a[100][100], c[100], n, start, u, p, k, m;
- bool viz[100];
- ifstream f("euler.in");
- void citire()
- {
- int i, j;
- f>>n>>m;
- while(f>>i>>j)
- a[i][j]=a[j][i]=1;
- }
- int grad(int x)
- {
- int i, s=0;
- for(i=1; i<=n; i++)
- s=s+a[i][x];
- return s;
- }
- void BF()
- {
- int i, x;
- p=u=1;
- c[p]=start;
- viz[start]=true;
- while(p<=u)
- {
- x=c[p];
- for(i=1; i<=n; i++)
- if(a[i][x]==1 && viz[i]==false)
- {
- viz[i]=true;
- u++;
- c[u]=i;
- }
- p++;
- }
- }
- int main()
- {
- int i;
- citire();
- cout<<"start: ";
- cin>>start;
- BF();
- for(i=1; i<=n; i++)
- if(grad(i)%2==0)
- k++;
- if(k==n && u==n)
- cout<<endl<<"Este graf Eulerian.";
- else cout<<"Nu este graf Eulerian.";
- }
- /*
- 6 10
- 1 2
- 1 6
- 2 3
- 2 5
- 2 6
- 3 4
- 3 5
- 3 6
- 4 5
- 5 6
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement