Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- int a[105], b[105], c[105], n, check[105], ma, total;
- void start(int x) {
- int ind = 0, start = x;
- while (true) {
- check[x]++;
- x = c[x];
- if (x == start) break;
- ind++;
- }
- ma = max(ind, ma);
- if (ind != 0) total++;
- }
- int main() {
- scanf("%d", &n);
- for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
- for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
- for (int i = 1; i <= n; i++) {
- for (int j = 1; j <= n; j++) {
- if (a[i] == b[j]) c[i] = j;
- }
- }
- for (int i = 1; i <= n; i++) {
- if (check[i] == 0) {
- start(i);
- }
- }
- if (total == 0 && ma == 0) printf("0 -1");
- else printf("%d %d", total, ma + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement