Buggy python submission (verdict: Runtime Error):
import numpy as np
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = np.array([-1] * n)
numberindex = set()
realnumber = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber.add(lis[a]-1)
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        ans += len(realnumber & numberindex)
        realnumber,numberindex = set(),set()
print(ans)

Fixed submission:
import numpy as np
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = np.array([-1] * n)
numberindex = set()
realnumber = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber.add(lis[a]-1)
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        ans += len(realnumber & numberindex)
        realnumber,numberindex = set(),set()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = np.array([-1] * n)
numberindex = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        realnumber = np.array([0] * n)
        numberindex.add(i)
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber[lis[a]-1] = 1
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        for num in numberindex:
            if realnumber[num] == 1:
                ans += 1
        numberindex = set()
print(ans)

Fixed submission:
import numpy as np
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = np.array([-1] * n)
numberindex = set()
realnumber = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber.add(lis[a]-1)
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        ans += len(realnumber & numberindex)
        realnumber,numberindex = set(),set()
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = np.array([-1] * n)
numberindex = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        realnumber = np.array([0] * n)
        numberindex.add(i)
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber[lis[a]-1] = 1
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        for num in numberindex:
            if realnumber[num] == 1:
                ans += 1
        numberindex = set()
print(ans)

Fixed submission:
import numpy as np
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = np.array([-1] * n)
numberindex = set()
realnumber = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber.add(lis[a]-1)
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        ans += len(realnumber & numberindex)
        realnumber,numberindex = set(),set()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = [-1] * n
numberindex = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        realnumber = [0] * n
        numberindex.add(i)
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber[lis[a]-1] = 1
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        for num in numberindex:
            if realnumber[num] == 1:
                ans += 1
        numberindex = set()

print(ans)

Fixed submission:
import numpy as np
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = np.array([-1] * n)
numberindex = set()
realnumber = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber.add(lis[a]-1)
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        ans += len(realnumber & numberindex)
        realnumber,numberindex = set(),set()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = [-1] * n
numberindex = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        realnumber = [0] * n
        numberindex.add(i)
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber[lis[a]-1] = 1
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        for num in numberindex:
            if realnumber[num] == 1:
                ans += 1
        numberindex = set()

print(ans)

Fixed submission:
import numpy as np
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = np.array([-1] * n)
numberindex = set()
realnumber = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber.add(lis[a]-1)
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        ans += len(realnumber & numberindex)
        realnumber,numberindex = set(),set()
print(ans)