Advertisement
a53

ctc_impar

a53
May 15th, 2022
119
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.  
  3. using namespace std;
  4. int n, m, a[105][105], ctc[105], s[105], p[105], nrc, sol;
  5. void df1(int x)
  6. {
  7. s[x] = 1;
  8. for(int i =1 ; i <= n ; i ++)
  9. if(s[i] == 0 && a[x][i] == 1)
  10. df1(i);
  11. }
  12.  
  13. void df2(int x)
  14. {
  15. p[x] = 1;
  16. for(int i =1 ; i <= n ; i ++)
  17. if(p[i] == 0 && a[i][x] == 1)
  18. df2(i);
  19. }
  20. int main()
  21. {
  22. ios_base::sync_with_stdio(0);
  23. cin.tie(0);
  24. cout.tie(0);
  25. int i, j;
  26. cin>>n>>m;
  27. while(m)
  28. {
  29. cin>>i>>j;
  30. a[i][j]=1;
  31. m --;
  32. }
  33. for(int i = 1 ; i <= n ; ++i)
  34. if(ctc[i] == 0)
  35. {
  36. for(int j = 1; j <= n ; ++j)
  37. s[j] = p[j] = 0;
  38. nrc ++;
  39. df1(i);
  40. df2(i);
  41. for(int j = 1; j <= n ; ++j)
  42. if(s[j] == 1 && p[j] == 1)
  43. ctc[j] = nrc;
  44. }
  45. for(int i =1 ; i <= nrc ; ++i)
  46. {
  47. int cnt=0;
  48. for(int j =1 ; j <= n ; ++j)
  49. if(ctc[j] == i)
  50. cnt++;
  51. if(cnt%2)
  52. sol++;
  53. }
  54. cout<<sol;
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement