Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,m,k=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in range(m)]
  cd=[list(map(int,input().split())) for _ in range(k)]
  friend=[[]for _ in range(n)]
  block=[[]for _ in range(n)]
  for a,b in ab:
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
  for c,d in cd:
    block[c-1].append(d-1)
    block[d-1].append(c-1)
  # 友達連結内でかつ友達でもブロックでもない。
  # 友達連結グループわけ
  ans=[0]*n
  seen=[0]*n
  for t in range(n):
    if seen[t]==1:
      continue
    member=[]
    todo=[t]
    seen[t]=1
    while todo:
      t=todo.pop()
      member.append(t)
      f=friend[t]
      for fi in f:
        if seen[fi]==0:
          todo.append(fi)
          seen[fi]=1
    mn=len(member)
    for m in member:
      ans[m]=mn-len(set(block[m]).intersection(set(member)))-len(friend[m])-1
  print(' '.join(map(str,ans)))
if __name__=='__main__':
  main()


Fixed submission:
import sys
input = sys.stdin.readline
def main():
  n,m,k=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in range(m)]
  cd=[list(map(int,input().split())) for _ in range(k)]
  gf=[[]for _ in range(n)]
  for a,b in ab:
    gf[a-1].append(b-1)
    gf[b-1].append(a-1)
  gb=[[]for _ in range(n)]
  for c,d in cd:
    gb[c-1].append(d-1)
    gb[d-1].append(c-1)
  seen=[0]*n
  ans=[0]*n
  for i in range(n):
    c=set([i])
    if seen[i]==0:
      todo=[i]
      while todo:
        e=todo.pop()
        l=gf[e]
        for li in l:
          if seen[li]==0:
            todo.append(li)
            seen[li]=1
            c.add(li)
      base=len(c)-1
      for ci in c:
        ans[ci]=base
        for fb in gb[ci]+gf[ci]:
          if fb in c:
            ans[ci]-=1
  print(' '.join(map(str,ans)))
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,m,k=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in range(m)]
  cd=[list(map(int,input().split())) for _ in range(k)]
  friend=[[]for _ in range(n)]
  block=[[]for _ in range(n)]
  for a,b in ab:
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
  for c,d in cd:
    block[c-1].append(d-1)
    block[d-1].append(c-1)
  # 友達連結内でかつ友達でもブロックでもない。
  # 友達連結グループわけ
  ans=[0]*n
  seen=[0]*n
  for t in range(n):
    if seen[t]==1:
      continue
    member=[]
    todo=[t]
    seen[t]=1
    while todo:
      t=todo.pop()
      member.append(t)
      f=friend[t]
      for fi in f:
        if seen[fi]==0:
          todo.append(fi)
          seen[fi]=1
    mn=len(member)
    for m in member:
      ans[m]=mn-len([mi for mi in block[m] if mi in member])-len(friend[m])-1
  print(' '.join(map(str,ans)))
if __name__=='__main__':
  main()


Fixed submission:
import sys
input = sys.stdin.readline
def main():
  n,m,k=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in range(m)]
  cd=[list(map(int,input().split())) for _ in range(k)]
  gf=[[]for _ in range(n)]
  for a,b in ab:
    gf[a-1].append(b-1)
    gf[b-1].append(a-1)
  gb=[[]for _ in range(n)]
  for c,d in cd:
    gb[c-1].append(d-1)
    gb[d-1].append(c-1)
  seen=[0]*n
  ans=[0]*n
  for i in range(n):
    c=set([i])
    if seen[i]==0:
      todo=[i]
      while todo:
        e=todo.pop()
        l=gf[e]
        for li in l:
          if seen[li]==0:
            todo.append(li)
            seen[li]=1
            c.add(li)
      base=len(c)-1
      for ci in c:
        ans[ci]=base
        for fb in gb[ci]+gf[ci]:
          if fb in c:
            ans[ci]-=1
  print(' '.join(map(str,ans)))
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
cd=[list(map(int,input().split())) for _ in range(k)]
friend=[[]for _ in range(n)]
block=[[]for _ in range(n)]
for a,b in ab:
  friend[a-1].append(b-1)
  friend[b-1].append(a-1)
for c,d in cd:
  block[c-1].append(d-1)
  block[d-1].append(c-1)
# 友達連結内でかつ友達でもブロックでもない。
# 友達連結グループわけ
ans=[0]*n
seen=[0]*n
while 0 in seen:
  member=[]
  t=seen.index(0)
  todo=[t]
  seen[t]=1
  while todo:
    t=todo.pop()
    member.append(t)
    f=friend[t]
    for fi in f:
      if seen[fi]==0:
        todo.append(fi)
        seen[fi]=1
  for m in member:
    ans[m]=len([mi for mi in member if mi not in block[m]])-len(friend[m])-1
print(' '.join(map(str,ans)))

Fixed submission:
import sys
input = sys.stdin.readline
def main():
  n,m,k=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in range(m)]
  cd=[list(map(int,input().split())) for _ in range(k)]
  gf=[[]for _ in range(n)]
  for a,b in ab:
    gf[a-1].append(b-1)
    gf[b-1].append(a-1)
  gb=[[]for _ in range(n)]
  for c,d in cd:
    gb[c-1].append(d-1)
    gb[d-1].append(c-1)
  seen=[0]*n
  ans=[0]*n
  for i in range(n):
    c=set([i])
    if seen[i]==0:
      todo=[i]
      while todo:
        e=todo.pop()
        l=gf[e]
        for li in l:
          if seen[li]==0:
            todo.append(li)
            seen[li]=1
            c.add(li)
      base=len(c)-1
      for ci in c:
        ans[ci]=base
        for fb in gb[ci]+gf[ci]:
          if fb in c:
            ans[ci]-=1
  print(' '.join(map(str,ans)))
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
cd=[list(map(int,input().split())) for _ in range(k)]
friend=[[]for _ in range(n)]
block=[[]for _ in range(n)]
for a,b in ab:
  friend[a-1].append(b-1)
  friend[b-1].append(a-1)
for c,d in cd:
  block[c-1].append(d-1)
  block[d-1].append(c-1)
# 友達連結内でかつ友達でもブロックでもない。
# 友達連結グループわけ
friend_group=[[] for _ in range(n)]
seen=[0]*n
while 0 in seen:
  member=[]
  t=seen.index(0)
  todo=[t]
  seen[t]=1
  while todo:
    t=todo.pop()
    member.append(t)
    f=friend[t]
    for fi in f:
      if seen[fi]==0:
        todo.append(fi)
        seen[fi]=1
  mn=len(member)
  for m in member:
    friend_group[m]=len([mi for mi in member if mi!=m and mi not in friend[m]+block[m]])
print(' '.join(map(str,friend_group)))

Fixed submission:
import sys
input = sys.stdin.readline
def main():
  n,m,k=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in range(m)]
  cd=[list(map(int,input().split())) for _ in range(k)]
  gf=[[]for _ in range(n)]
  for a,b in ab:
    gf[a-1].append(b-1)
    gf[b-1].append(a-1)
  gb=[[]for _ in range(n)]
  for c,d in cd:
    gb[c-1].append(d-1)
    gb[d-1].append(c-1)
  seen=[0]*n
  ans=[0]*n
  for i in range(n):
    c=set([i])
    if seen[i]==0:
      todo=[i]
      while todo:
        e=todo.pop()
        l=gf[e]
        for li in l:
          if seen[li]==0:
            todo.append(li)
            seen[li]=1
            c.add(li)
      base=len(c)-1
      for ci in c:
        ans[ci]=base
        for fb in gb[ci]+gf[ci]:
          if fb in c:
            ans[ci]-=1
  print(' '.join(map(str,ans)))
if __name__=='__main__':
  main()