Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ifstream fin("graf.in");
  5. int a[100][100],viz[100],n,ok=1;
  6. void citire()
  7. {
  8. int i,j;
  9. fin>>n;
  10. while(fin>>i>>j)
  11. a[i][j]=a[j][i]=1;
  12. }
  13. int dfs(int x,int contor)
  14. {
  15. if(contor==0)
  16. viz[x]=1;
  17. for(int i=1; i<=n; i++)
  18. {
  19. if(viz[i]==0&&a[x][i]==1)
  20. {
  21. viz[i]=3-viz[x];
  22. return dfs(i,++contor);
  23. }
  24. if(viz[x]==viz[i]&&a[x][i]==1)
  25. return 0;
  26. }
  27. return 1;
  28. }
  29. int main()
  30. {
  31. citire();
  32. cout<<dfs(1,0);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement