Problem p02762 (python)

Fixed submission:
N, M, K = map(int,input().split())
uf = [-1 for _ in range(N)]
fc = [0] * N
bc = [0] * N
ans = [0] * N

def find(x):
    # x を引数に取り、xのroot番号を取得するメモ化再帰
    if uf[x] < 0:
        return x
    uf[x] = find(uf[x])
    return uf[x]

def unite(x, y):
    # x, y を引数に取り、x(自分)をy(相手)のrootに接続する関数
    x = find(x)
    y = find(y)
    if x == y:
        return
    if x < y:
        x , y = y, x
    uf[y] += uf[x]
    uf[x] = y

for m in range(M):
    a, b = map(int,input().split())
    fc[a-1] += 1
    fc[b-1] += 1
    unite(a-1, b-1)

for k in range(K):
    c, d = map(int,input().split())
    if find(c-1) == find(d-1):
        bc[c-1] += 1
        bc[d-1] += 1

for i in range(N):
    cnt = -uf[find(i)] - 1 - fc[i] - bc[i]
    ans[i] = cnt

print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**3)

N, M, K = map(int,input().split())
tree = [-1 for _ in range(N)]
fc = [0] * N
bc = [0] * N
ans = [0] * N

def find(x):
    # x を引数に取り、xのroot番号を取得するメモ化再帰
    if tree[x] < 0:
        return x
    tree[x] = find(tree[x])
    return tree[x]

def unite(x, y):
    # x, y を引数に取り、x(自分)をy(相手)のrootに接続する関数
    rootx = find(x)
    rooty = find(y)
    if rootx == rooty:
        return
    if rootx < rooty:
        x , y = y, x
    tree[rooty] += tree[rootx]
    tree[rootx] = rooty

for m in range(M):
    a, b = map(int,input().split())
    fc[a-1] += 1
    fc[b-1] += 1
    unite(a-1, b-1)

for k in range(K):
    c, d = map(int,input().split())
    if find(c-1) == find(d-1):
        bc[c-1] += 1
        bc[d-1] += 1

for i in range(N):
    cnt = -tree[find(i)] - 1 - fc[i] - bc[i]
    ans[i] = cnt

print(*ans)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int,input().split())
tree = [-1 for _ in range(N)]
fc = [0] * N
bc = [0] * N
ans = [0] * N

def find(x):
    # x を引数に取り、xのroot番号を取得するメモ化再帰
    if tree[x] < 0:
        return x
    tree[x] = find(tree[x])
    return tree[x]

def unite(x, y):
    # x, y を引数に取り、x(自分)をy(相手)のrootに接続する関数
    rootx = find(x)
    rooty = find(y)
    if rootx == rooty:
        return
    if rootx < rooty:
        x , y = y, x
    tree[rooty] += tree[rootx]
    tree[rootx] = rooty

for m in range(M):
    a, b = map(int,input().split())
    fc[a-1] += 1
    fc[b-1] += 1
    unite(a-1, b-1)

for k in range(K):
    c, d = map(int,input().split())
    if find(c-1) == find(d-1):
        bc[c-1] += 1
        bc[d-1] += 1

for i in range(N):
    cnt = -tree[find(i)] - 1 - fc[i] - bc[i]
    ans[i] = cnt

print(*ans)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int,input().split())
tree = [-1 for i in range(N)]
fc = [0 for i in range(N)]
bc = [0 for i in range(N)]
ans = [0 for i in range(N)]

def find(x):
    # x を引数に取り、xのroot番号を取得するメモ化再帰
    if tree[x] < 0:
        return x
    tree[x] = find(tree[x])
    return tree[x]

def unite(x, y):
    # x, y を引数に取り、x(自分)をy(相手)のrootに接続する関数
    rootx = find(x)
    rooty = find(y)
    if rootx == rooty:
        return
    if rootx < rooty:
        x , y = y, x
    tree[rooty] += tree[rootx]
    tree[rootx] = rooty

for i in range(M):
    a, b = map(int,input().split())
    fc[a-1] += 1
    fc[b-1] += 1
    unite(a-1, b-1)

for i in range(K):
    c, d = map(int,input().split())
    if find(c-1) == find(d-1):
        bc[c-1] += 1
        bc[d-1] += 1

for i in range(N):
    cnt = -tree[find(i)] - 1 - fc[i] - bc[i]
    ans[i] = cnt

print(*ans)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int,input().split())
tree = [-1 for i in range(N)]
fc = [0 for i in range(N)]
bc = [0 for i in range(N)]
ans = ""

def find(x):
    # x を引数に取り、xのroot番号を取得するメモ化再帰
    if tree[x] < 0:
        return x
    tree[x] = find(tree[x])
    return tree[x]

def unite(x, y):
    # x, y を引数に取り、x(自分)をy(相手)のrootに接続する関数
    rootx = find(x)
    rooty = find(y)
    if rootx == rooty:
        return
    if rootx < rooty:
        x , y = y, x
    tree[rooty] += tree[rootx]
    tree[rootx] = rooty
    return

for i in range(M):
    a, b = map(int,input().split())
    fc[a-1] += 1
    fc[b-1] += 1
    unite(a-1, b-1)

for i in range(K):
    c, d = map(int,input().split())
    if find(c-1) == find(d-1):
        bc[c-1] += 1
        bc[d-1] += 1

for i in range(N):
    cnt = -tree[find(i)] - 1 - fc[i] - bc[i]
    ans += str(cnt)

print(' '.join(ans))

Buggy submission (verdict: Runtime Error):
N, M, K = map(int,input().split())
frendunion = [[] for i in range(N)]
blockunion = [[] for i in range(N)]
tree = [-1 for i in range(N)]
bc = 0
ans = ""

def find(x):
    # x を引数に取り、xのroot番号を取得するメモ化再帰
    if tree[x] < 0:
        return x
    tree[x] = find(tree[x])
    return tree[x]

def unite(x, y):
    # x, y を引数に取り、x(自分)をy(相手)のrootに接続する関数
    rootx = find(x)
    rooty = find(y)
    if rootx == rooty:
        return
    if rootx < rooty:
        x , y = y, x
    tree[rooty] += tree[rootx]
    tree[rootx] = rooty
    return

for i in range(M):
    a, b = map(int,input().split())
    frendunion[a-1].append(b-1)
    frendunion[b-1].append(a-1)
    unite(a-1, b-1)

for i in range(K):
    c, d = map(int,input().split())
    blockunion[c-1].append(d-1)
    blockunion[d-1].append(c-1)

for i in range(N):
    for j in blockunion[i]:
        if find(j) == find(i):
            bc += 1
    cnt = -tree[find(i)] - 1 - len(frendunion[i]) - bc
    ans += str(cnt)
    bc = 0

print(' '.join(ans))