Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())

friend = [[] for _ in range(n)]
block = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
for _ in range(k):
    c, d = map(int, input().split())
    block[c-1].append(d-1)
    block[d-1].append(c-1)

ans = [0] * n #answer
seen = [0] * n #未探索なら0、探索済なら1
todo = [] #探索保留

#DFS
for i in range(n):
    if seen[i] == 0:
        element = [] #連結要素
        seen[i] = 1
        todo.append(i)
        element.append(i)
        size = 0

        while todo != []:
            for j in friend[todo[-1]]:
                if seen[j] == 0:
                    seen[j] = 1
                    todo.append(j)
                    element.append(j)
                    size += 1
                    break
            else:
                del todo[-1]

        for j in element:
            bl = 0
            for k in block[j]:
                if k in element:
                    bl += 1

            #size = len(element) - 1
            ans[j] = size - len(friend[j]) - bl
        
    print(ans[i])

Fixed submission:
# 参考URL https://note.nkmk.me/python-union-find/
class UnionFind():
    # parents
    # 各要素の親要素の番号を格納するリスト
    # 要素が根（ルート）の場合は-(そのグループの要素数)を格納する
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # find(x)
    # 要素xが属するグループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # union(x, y)
    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # same(x, y)
    # 要素x, yが同じグループに属するかどうかを返す
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # size(x)
    # 要素xが属するグループのサイズ（要素数）を返す
    def size(self, x):
        return -self.parents[self.find(x)]

import sys
def input():
    return sys.stdin.readline().strip()

n, m, k = map(int, input().split())
ans = [-1 for _ in range(n)]
uf = UnionFind(n)

for _ in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
    ans[a-1] -= 1
    ans[b-1] -= 1

for _ in range(k):
    c, d = map(int, input().split())
    if uf.same(c-1, d-1):
        ans[c-1] -= 1
        ans[d-1] -= 1

for i in range(n):
    ans[i] += uf.size(i)

print(' '.join(map(str, ans)))

Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())

friend = [[] for _ in range(n)]
block = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
for _ in range(k):
    c, d = map(int, input().split())
    block[c-1].append(d-1)
    block[d-1].append(c-1)

ans = [0] * n #answer
seen = [0] * n #未探索なら0、探索済なら1
todo = [] #探索保留

#DFS
for i in range(n):
    if seen[i] == 0:
        element = [] #連結要素
        seen[i] = 1
        todo.append(i)
        element.append(i)
        size = 0

        while todo != []:
            for j in friend[todo[-1]]:
                if seen[j] == 0:
                    seen[j] = 1
                    todo.append(j)
                    element.append(j)
                    size += 1
                    break
            else:
                del todo[-1]

        for j in element:
            bl = 0
            for k in block[j]:
                if k in element:
                    bl += 1

            #size = len(element) - 1
            ans[j] = size - len(friend[j]) - bl
        
    print(ans[i])

Fixed submission:
# 参考URL https://note.nkmk.me/python-union-find/
class UnionFind():
    # parents
    # 各要素の親要素の番号を格納するリスト
    # 要素が根（ルート）の場合は-(そのグループの要素数)を格納する
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # find(x)
    # 要素xが属するグループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # union(x, y)
    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # same(x, y)
    # 要素x, yが同じグループに属するかどうかを返す
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # size(x)
    # 要素xが属するグループのサイズ（要素数）を返す
    def size(self, x):
        return -self.parents[self.find(x)]

import sys
def input():
    return sys.stdin.readline().strip()

n, m, k = map(int, input().split())
ans = [-1 for _ in range(n)]
uf = UnionFind(n)

for _ in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
    ans[a-1] -= 1
    ans[b-1] -= 1

for _ in range(k):
    c, d = map(int, input().split())
    if uf.same(c-1, d-1):
        ans[c-1] -= 1
        ans[d-1] -= 1

for i in range(n):
    ans[i] += uf.size(i)

print(' '.join(map(str, ans)))

Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())

friend = [[] for _ in range(n)]
block = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
for _ in range(k):
    c, d = map(int, input().split())
    block[c-1].append(d-1)
    block[d-1].append(c-1)

size = [0] * n
seen = [0] * n #未探索なら0、探索済なら1
todo = [] #探索保留

#DFS
for i in range(n):
    if seen[i] == 0:
        element = [] #連結要素
        seen[i] = 1
        todo.append(i)
        element.append(i)
        while todo != []:
            for j in friend[todo[-1]]:
                if seen[j] == 0:
                    seen[j] = 1
                    todo.append(j)
                    element.append(j)
                    break
            else:
                del todo[-1]
        length = len(element)
        for j in element:
            block[j] = [k for k in block[j] if k in element]
            size[j] = length - len(friend[j]) - len(block[j]) - 1
        
    print(size[i])

Fixed submission:
# 参考URL https://note.nkmk.me/python-union-find/
class UnionFind():
    # parents
    # 各要素の親要素の番号を格納するリスト
    # 要素が根（ルート）の場合は-(そのグループの要素数)を格納する
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # find(x)
    # 要素xが属するグループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # union(x, y)
    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # same(x, y)
    # 要素x, yが同じグループに属するかどうかを返す
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # size(x)
    # 要素xが属するグループのサイズ（要素数）を返す
    def size(self, x):
        return -self.parents[self.find(x)]

import sys
def input():
    return sys.stdin.readline().strip()

n, m, k = map(int, input().split())
ans = [-1 for _ in range(n)]
uf = UnionFind(n)

for _ in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
    ans[a-1] -= 1
    ans[b-1] -= 1

for _ in range(k):
    c, d = map(int, input().split())
    if uf.same(c-1, d-1):
        ans[c-1] -= 1
        ans[d-1] -= 1

for i in range(n):
    ans[i] += uf.size(i)

print(' '.join(map(str, ans)))