Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5. int a[105], b[105], c[105], n, check[105], ma, total;
  6.  
  7. void start(int x) {
  8. int ind = 0, start = x;
  9. while (true) {
  10. check[x]++;
  11. x = c[x];
  12. if (x == start) break;
  13. ind++;
  14. }
  15. ma = max(ind, ma);
  16. if (ind != 0) total++;
  17. }
  18.  
  19. int main() {
  20. scanf("%d", &n);
  21. for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  22. for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  23. for (int i = 1; i <= n; i++) {
  24. for (int j = 1; j <= n; j++) {
  25. if (a[i] == b[j]) c[i] = j;
  26. }
  27. }
  28. for (int i = 1; i <= n; i++) {
  29. if (check[i] == 0) {
  30. start(i);
  31. }
  32. }
  33. if (total == 0 && ma == 0) printf("0 -1");
  34. else printf("%d %d", total, ma + 1);
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement