Advertisement
a53

bona

a53
May 4th, 2019
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. # include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct locatie
  5. {
  6. short l, c, lf, cf;
  7. }juc[10001];
  8.  
  9. bool ap[10001];
  10. int n, m;
  11.  
  12. int next(short j)
  13. {
  14. short i;
  15. for (i=1;i<=m;++i)
  16. if (!ap[i])
  17. if (juc[j].lf==juc[i].l && juc[j].cf==juc[i].c) return i;
  18. return -1;
  19. }
  20.  
  21. int main()
  22. {
  23. int i, j, k, l, c, lf, cf, n1;
  24. freopen("bona.in", "r", stdin);
  25. freopen("bona.out", "w", stdout);
  26.  
  27. scanf("%d %d", &n,&m);
  28. k = m;
  29. for (i=1; i<=m; ++i){
  30.  
  31. scanf("%d %d %d %d", &l, &c, &lf, &cf);
  32. if (l == lf && c == cf) {
  33. --k;
  34. ap[i] = 1;
  35. }
  36. else {
  37. juc[i].l = l; juc[i].c = c;
  38. juc[i].lf = lf;juc[i].cf = cf;
  39. }
  40. }
  41. n1 = 0;
  42. for (i=1; i<=m; ++i)
  43. if (!ap[i]) {
  44. j = next(i);
  45. while (j != -1 && j != i) {
  46. ap[j] = 1;
  47. j = next(j);
  48. }
  49. if (i == j) ++n1;
  50. }
  51.  
  52. printf("%d\n", k - n1);
  53. printf("%d\n", k + n1);
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement