Problem:


Score : 200 points

Problem Statement

There are N cities and M roads.
The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally.
There may be more than one road that connects the same pair of two cities.
For each city, how many roads are connected to the city?

Constraints

2≤N,M≤50

1≤a_i,b_i≤N

a_i ≠ b_i

All input values are integers.

Input

Input is given from Standard Input in the following format:  

N M
a_1 b_1
:  
a_M b_M

Output

Print the answer in N lines.
In the i-th line (1≤i≤N), print the number of roads connected to city i.

Sample Input 1

4 3
1 2
2 3
1 4

Sample Output 1

2
2
1
1

City 1 is connected to the 1-st and 3-rd roads.

City 2 is connected to the 1-st and 2-nd roads.

City 3 is connected to the 2-nd road.

City 4 is connected to the 3-rd road.

Sample Input 2

2 5
1 2
2 1
1 2
2 1
1 2

Sample Output 2

5
5

Sample Input 3

8 8
1 2
3 4
1 5
2 8
3 7
5 2
4 1
6 8

Sample Output 3

3
3
2
2
2
1
1
2



Sample input:
4 3
1 2
2 3
1 4


Sample output:
2
2
1
1

Submission status: Accepted

Solution code:
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
ans = [0 for _ in range(N)]
for i in range(M):
    a, b = MAP()
    ans[a - 1] += 1
    ans[b - 1] += 1

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())

Ans = [0] * N

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

for ans in Ans:
	  print(ans)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
array = [list(map(int,input().split())) for i in range(b)]
count = [0]*a
for i in range(a):
    for j in range(b):
        if i+1 in array[j]:
            count[i] += 1
for i in range(a):
    print(count[i])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ab = []
for _ in range(M):
    ab.extend(list(map(int,(input().split()))))

for j in range(1,N+1):
    print(ab.count(j))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
L=[0]*a
for i in range(b):
  x,y=map(int,input().split())
  L[x-1]+=1
  L[y-1]+=1
for i in range(a):
  print(L[i])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(M)]
num=[0 for i in range(N)]
for i in range(M):
    num[ab[i][0]-1]+=1
    num[ab[i][1]-1]+=1

for i in range(N):
    print(num[i])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
lst = [[] for i in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    lst[a-1].append(b-1)
    lst[b-1].append(a-1)

for v in lst:
    print(len(v))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
vec = [0]*N
for i in range(M):
  A,B = map(int,input().split())
  vec[A-1] += 1
  vec[B-1] += 1
for j in range(N):
  print(vec[j])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[0]*(N+1)
 
for _ in range(M):
  a,b=map(int,input().split())
  A[a]+=1
  A[b]+=1
 
for i in range(1,N+1):
  print(A[i])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ans = [0 for _ in range(N)]
for _ in range(M):
  a,b = map(int,input().split())
  ans[a-1] += 1
  ans[b-1] += 1
for i in range(N):
  print(ans[i])

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    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

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,m = lr()
count = [[0 for i in range(n)] for h in range(n)]
for i in range(m):
    a,b  = lr()
    a-=1
    b-=1
    a,b = min(a,b), max(a,b)
    count[a][b] += 1
    count[b][a] += 1
for i in range(n):
    print(sum(count[i]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = [0] * n
for i in range(m):
  a, b = map(int, input().split())
  ans[a-1] += 1
  ans[b-1] += 1
for i in range(n):
  print(ans[i])

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
ans = [0] * n
for _ in range(m):
    a, b = [int(x) - 1 for x in input().split()]
    ans[a] += 1
    ans[b] += 1
print("\n".join([str(x) for x in ans]))

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
ans = [0] * n
for _ in range(m):
    a, b = [int(x) - 1 for x in input().split()]
    ans[a] += 1
    ans[b] += 1
print(*ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
R = [0]*N
for i in range(M):
  x,y = map(int,input().split())
  R[x-1] += 1
  R[y-1] += 1
for i in R:
  print(i)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *AB = map(int, read().split())
    ans = [0] * N
    for a, b in zip(*[iter(AB)] * 2):
        ans[a - 1] += 1
        ans[b - 1] += 1

    print(*ans, sep='\n')

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[0]*(n+1)
for i in range(m):
  a,b=map(int,input().split())
  l[a]+=1
  l[b]+=1
for i in range(1,n+1):
  print(l[i])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
li=[0]*N
for i in range(M):
    a,b=map(int,input().split())
    li[a-1]+=1
    li[b-1]+=1
for j in range(N):
    print(li[j])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
c = [0] * N
for _ in range(M):
    a, b = map(int, input().split())
    c[a-1] += 1
    c[b-1] += 1
for i in range(N):
    print(c[i])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
li=[0]*N
for i in range(M):
    a,b=map(int,input().split())
    li[a-1]+=1
    li[b-1]+=1
for j in range(N):
    print(li[j])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
l=[0]*N

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

for i in range(N):
  print(l[i])

Submission status: Accepted

Solution code:
from collections import defaultdict

n,m=map(int,input().split())
r=[list(map(int,input().split())) for _ in range(m)]
d=defaultdict(int)
for x in r:
  d[x[0]]+=1
  d[x[1]]+=1

for i in range(1,n+1):
  print(d[i])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a,b=[0]*M,[0]*M
for i in range(M):a[i],b[i]=map(int,input().split())
for i in range(N):print(a.count(i+1)+b.count(i+1))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

res = [0] * n
for _ in range(m):
  a, b = map(int, input().split())
  res[a-1] += 1
  res[b-1] += 1

for v in res:
  print(v)

Submission status: Accepted

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,M = MI()
from collections import defaultdict

d = defaultdict(int)
for i in range(M):
    a,b = MI()
    d[a] += 1
    d[b] += 1

for i in range(1,N+1):
    print(d[i])

Submission status: Accepted

Solution code:
n, m = map(int , input().split())
routes = [0 for i in range(n)]

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

for r in routes:
  print(r)

Submission status: Accepted

Solution code:
#53
N,M = map(int,input().split())
load = [0 for i in range(N)]

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
k = [i for i in range(1, n + 1)]
v = [0] * n
d = dict(zip(k, v))

for _ in range(m):
    a, b = map(int, input().split())
    d[a] += 1
    d[b] += 1

for x in d.values():
    print(x)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
List = []
for i in range (M):
  List.append(list(map(int, input().split())))
resList = [0]*N
for i in range(M):
  resList[List[i][0]-1]+=1
  resList[List[i][1]-1]+=1
for element in resList:
  print(element)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a-=1; b-=1
    g[a].append(b)
    g[b].append(a)

for i in range(n):
    print(len(g[i]))

Submission status: Accepted

Solution code:
N, M = input().split(' ')
N = int(N)
M = int(M)
citys = []
for i in range(M):
  a, b = input().split(' ')
  a = int(a)
  b = int(b)
  citys.append(a)
  citys.append(b)
for i in range(1, N+1):
  print(citys.count(i))

Submission status: Accepted

Solution code:
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N, M = MI()
city = [[] for _ in range(N)]

for _ in range(M):
    a, b = MI()
    city[a - 1].append(b - 1)
    city[b - 1].append(a - 1)
    
for c in city:
    print(len(c))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())                    
route_lists = [input().split() for i in range(m)]   
new_lists = []                                      
for i in route_lists:                               
  for j in range(2):                                
    new_lists.append(i[j])                          
                                                                                      
for i in range(1, n+1, 1):                          
  print(new_lists.count(str(i)))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())                    
route_lists = [input().split() for i in range(m)]   
new_lists = []                                      
for i in route_lists:                               
  for j in range(2):                                
    new_lists.append(i[j])                          
                                                    
new_lists.sort()                                    
for i in range(1, n+1, 1):                          
  print(new_lists.count(str(i)))

Submission status: Accepted

Solution code:
N,_,*L=map(int,open(0).read().split())
for n in range(N):print(L.count(n+1))

Submission status: Accepted

Solution code:
N,_,*L=map(int,open(0).read().split())
A=[0]*N
for l in L: A[l-1]+=1
print(*A,sep='\n')

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
road_num = [0] * N
for _ in range(M):
    a,b = map(int,input().split())
    road_num[a-1] += 1
    road_num[b - 1] += 1
for i in range(N):
    print(road_num[i])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

Road = []
for _ in range(m):
    a, b = map(int, input().split())
    Road.append((a, b))

tmp = sorted(Road)
#print(tmp)

ans = [0]*n
for t in tmp:
  ans[t[0]-1] += 1
  ans[t[1]-1] += 1

for a in ans:
  print(a)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())

ans = [0] * N

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

print(*ans, sep='\n')

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().split()]
road = [0]*N
for _ in range(M):
    a,b = [int(i)-1 for i in input().split()]
    road[a] += 1
    road[b] += 1
print("\n".join(map(str, road)))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
nodes = [input().split() for _ in range(m)]

node_num = {str(i): 0 for i in range(1, n + 1)}
for node in nodes:
    node_num[node[0]] += 1
    node_num[node[1]] += 1

for i in range(1, n + 1):
    print(node_num[str(i)])

Submission status: Accepted

Solution code:
MM = input().split()
N = int(MM[0])
M = int(MM[1])
list1 = []
for i in range(M):
  aa = input().split()
  a = int(aa[0])
  b = int(aa[1])
  list1.append(a)
  list1.append(b)
for i in range(1,N+1):
  ans = list1.count(i)
  print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split(" "))
nn = [0 for i in range(n)]
for i in range(m):
    a, b = map(int, input().split(" "))
    nn[a - 1] += 1
    nn[b - 1] += 1
for i in nn:
    print(i)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
c = []
for i in range(M):
  c.extend(list(map(int,input().split())))
for j in range(N):
  print(c.count(j+1))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
c = []
for i in range(M):
  a,b = map(int,input().split())
  c.append(a)
  c.append(b)
for j in range(N):
  print(c.count(j+1))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
city = [0] * n
for i in range(m) :
    a, b = map(int, input().split())
    city[a-1] += 1
    city[b-1] += 1
for i in range(n) :
    print(city[i])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
tmp=[]
for _ in range(m):
    tmp.append(list(map(int,input().split())))
for i in range(1,n+1):
    print(sum(j.count(i) for j in tmp))

Submission status: Accepted

Solution code:
s = input().split()

n = int(s[0])
m = int(s[1])

citys = []
for i in range(n):
    citys.append(0)


for i in range(m):
    p = input().split()
    x = int(p[0])
    y = int(p[1])
    citys[x - 1] += 1
    citys[y - 1] += 1

for i in range(len(citys)):
    print(citys[i])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

lis = [0]*(n)

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

for j in range(n):
    print(lis[j])

Submission status: Accepted

Solution code:
n,m,*ab = map(int, open(0).read().split())

from collections import Counter

c = Counter(ab)

for i in range(1,n+1):
    print(c[i])

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
city = [0]*N
for _ in range(M):
  a_i, b_i = map(int,input().split())
  city[a_i-1]+=1
  city[b_i-1]+=1
for i in range(N):
  print(city[i])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = []
for i in range(m):
    a.extend(list(map(int,input().split())))
for i in range(1,n+1):
    print(a.count(i))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
r = [0]*n
for i in range(m):
  a,b = map(int,input().split())
  r[a-1]+=1
  r[b-1]+=1
for i in r: print(i)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
cnt = [0] * N
for _ in range(M):
    a, b = map(int, input().split())
    cnt[a-1] += 1
    cnt[b-1] += 1
for c in cnt:
    print(c)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

ab =[[] for _ in range(n)]

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

for i in ab:
    print(len(i))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
d={}
for i in range(n):
    d[i]=0
for i in range(m):
    a,b=map(int,input().split())
    d[a-1]+=1
    d[b-1]+=1
for i in range(n):
    print(d[i])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
route = [[0 for i in range(N)] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    route[a-1][b-1] += 1
    route[b-1][a-1] += 1
for i in route:
    print(sum(i))

Submission status: Accepted

Solution code:
n, m = [int(w) for w in input().split()]

ed = [0] * n
for i in range(m):
    a, b = [int(w) - 1 for w in input().split()]
    ed[a] += 1
    ed[b] += 1
print("\n".join([str(w) for w in ed]))

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().split()]
list = []

for i in range(M):
  a,b = [int(i) for i in input().split()]
  list.append(a)
  list.append(b)

for i in range(1,N+1):
  print(list.count(i))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
(n, m), *r = [[*map(int, i.split())] for i in open(0)]
for i in range(1, n + 1):
    print(sum(r, []).count(i))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
lst=[0]*n

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

for i in lst:
    print(i)

Submission status: Accepted

Solution code:
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
Load = [0 for i in range(N)]
# print(Load)

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

for i in range(N):
    print(Load[i])

# print(Load)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = []
for _ in range(m):
    l += list(map(int, input().split()))

for i in range(1, n+1):
    print(l.count(i))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
loads = [list(map(int, input().split())) for _ in range(m)]
ans = [0] * (n + 1)
for i in range(m):
    for j in loads[i]:
        ans[j] += 1
for out in range(1, n + 1):
    print(ans[out])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [0]*N

for m in range(M):
  a,b = map(int,input().split())
  A[a-1]+=1
  A[b-1]+=1
print(*A,sep="\n")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
lst = [0] * n
for i in range(m):
  a, b = map(int, input().split())
  lst[a - 1] += 1
  lst[b - 1] += 1
for i in range(n):
  print(lst[i])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(m)]
a,b = [list(i) for i in zip(*l)]

for i in range(1,n+1):
    t = 0
    t += a.count(i)
    t += b.count(i)
    print(t)

Submission status: Accepted

Solution code:

N,M = map(int,input().split())
adj = [[0]*N for _ in range(N)]
intx = lambda x: int(x)-1
for i in range(M):
    a,b = map(intx,input().split())
    #print(a,b)
    adj[a][b] += 1
    adj[b][a] += 1
#print(adj)
for i in range(N): 
    print(sum(adj[i]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
load = []
for _ in range(m):
	load.extend(map(int, input().split()))

for i in range(n):
    print(load.count(i+1))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
ab = [map(int, input().split()) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]

for i in range(1, n + 1):
    ac = a.count(i)
    bc = b.count(i)
    print(ac + bc)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
NRD = list(0 for i in range(n))
for i in range(m):
    r1, r2 = map(int, input().split())
    NRD[r1 - 1] += 1
    NRD[r2 - 1] += 1
for i in range(n):
    print(NRD[i])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
RD = list(list(map(int, input().split())) for _ in range(m))
for i in range(1, n + 1):
    ans = 0
    for j in RD:
        ans += j.count(i)
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
counter = [0]*N
for _ in range(M):
    a, b = map(int, input().split())
    counter[a-1] += 1
    counter[b-1] += 1

for c in counter:
    print(c)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
a = 0
b = 0
A = []
B = []
city = [0]*N
for i in range(M):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)
for i in range(M):
    city[A[i] - 1] += 1
    city[B[i] - 1] += 1
for i in range(N):
    print(city[i])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
roads = [0]*N
for i in range(M):
  a,b = map(int,input().split())
  roads[a-1]+=1
  roads[b-1]+=1
for i in roads:
  print(i)

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split()))
lis = []
for i in range(N):
    lis.append([i+1])
for i in range(M):
    a,b = list(map(int,input().split()))
    lis[a-1].append(b)
    lis[b-1].append(a)
for i in range(N):
    print(len(lis[i])-1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
deg=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    deg[a]+=1
    deg[b]+=1
print(*deg,sep="\n")

Submission status: Accepted

Solution code:
N, M = map(int, input().split(' '))

ans = []
for n in range(N):
    ans.append(0)

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

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
n,m=[int(i) for i in input().split()]

#都市nがキー
keys=[i for i in range(1,n+1)]
#print(keys)
values=[0]*n
#print(values)
a_dic=dict(zip(keys,values))
#print(a_dic)

for i in range(m):
    a,b=[int(i) for i in input().split()]
    #print(a,b)
    a_dic[a]+=1
    a_dic[b]+=1


#print(a_dic)

#都市n個のvalueを出力していく    
for i in range(1,n+1):
    print(a_dic[i])

Submission status: Accepted

Solution code:
n,m = map(int, input().split())

li = []
for i in range(m):
  a,b = map(int, input().split())
  li.append(a)
  li.append(b)

for i in range(1, n+1):
  print(li.count(i))

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,m = i2()
ans = [0]*n
for i in range(m):
	a,b = i2()
	ans[a-1] += 1
	ans[b-1] += 1 
	
for i in range(n):
	print(ans[i])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
cities = {}
for i in range(n):
    cities[i+1] = 0
for j in range(m):
    a, b = map(int, input().split())
    cities[a] += 1
    cities[b] += 1
for k in cities.values():
    print(k)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
g = [[] * n for _ in range(n)]

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

for path in g:
    print(len(path))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
dp=[0]*N
for i in range(M):
  a,b=map(int,input().split())
  dp[a-1]+=1
  dp[b-1]+=1
for j in range(N):
  print(dp[j])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
li=[]
for i in range(M):
    a,b=map(int,input().split())
    li.append(a)
    li.append(b)
ans=[0]*N
for j in range(1,N+1):
    cj=li.count(j)
    ans[j-1]=cj
for k in range(N):
    print(ans[k])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)
for g in G:
    print(len(g))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
road = [0 for _ in range(N)]

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

for i in range(N):
    print(road[i])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
B=[0]*(N+1)
for _ in range(M):
    u,v=map(int,input().split())
    B[u]+=1
    B[v]+=1

for a in range(1,N+1):
    print(B[a])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(M)]
R = sum(A,[])

for i in range(1,N+1):
    print(R.count(i))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N, M = map(int, input().split())

road_count_list = [0] * N

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

print(*road_count_list, sep='\n')

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for n in range(m)]
cnt = [0]*n
cnt.insert(0,"X")
for i in range(m):
	for j in range(2):
		cnt[ab[i][j]] += 1
cnt.pop(0)
for s in range(len(cnt)):
	print(cnt[s])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
x = [list(map(int,input().split())) for i in range(m)]
y = []
z = []

for k in range(m):
    y = y + x[k]

for l in range(1,n+1):
    z = z + [y.count(l)]
    
for p in z:
    print(p)

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
road_num=[0]*n
for i in range(m):
  a,b=map(int, input().split())
  road_num[a-1]+=1
  road_num[b-1]+=1
for i in range(n):
  print(road_num[i])

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
R = [0 for _ in range(N)]
for _ in range(M):
    a, b = [int(i) for i in input().split()]
    R[a - 1] += 1
    R[b - 1] += 1
for i in range(N):
    print(R[i])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
b = []
for i in range(m):
  a_, b_ = map(int, input().split())
  a.append(a_)
  b.append(b_)

for i in range(1, n+1):
  c = a.count(i)
  d = b.count(i)
  print(c+d)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

citys = {i: 0 for i in range(1, N+1)}

for _ in range(M):
    a, b = map(int, input().split())
    citys[a] += 1
    citys[b] += 1
    
for num in citys.values():
    print(num)

Submission status: Accepted

Solution code:
from collections import Counter
N, M = map(int, input().split())
dis_list = []
my_count = Counter()
for i in range(1, N + 1):
    my_count[i] = 0
for i in range(M):
    a, b = map(int, input().split())
    my_count[a] += 1
    my_count[b] += 1
my_count = sorted(my_count.items())
for i in range(N):
    print(my_count[i][1])

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    count = [0] * n
    for _ in range(m):
        a, b = map(int, input().split())
        count[a-1] += 1
        count[b-1] += 1

    print(*count, sep="\n")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = N*[0]

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

print(*A,sep="\n")

Submission status: Accepted

Solution code:

url = "https://atcoder.jp//contests/abc061/tasks/abc061_b"

def main():
    t = list(map(int, input().split()))
    rode = [0] * t[0]
    for i in range(t[1]):
        r = list(map(int, input().split()))
        rode[r[0]-1] += 1
        rode[r[1]-1] += 1
    for v in rode:
        print(v)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a, b = [], []
for i in range(m):
  p, q = map(int, input().split())
  a.append(p)
  b.append(q)

for i in range(n):
  print(a.count(i + 1) + b.count(i + 1))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

pairs = []
for i in range(M):
    pairs.append(list(map(int, input().split())))

for i in range(1,N+1):
    s = 0
    for pair in pairs:
        if i in pair:
            s += 1
    print(s)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
R = list(list(map(int, input().split())) for _ in range(m))
for i in range(1, n+1):
    print(sum(R, []).count(i))

Submission status: Accepted

Solution code:
def resolve():
    from collections import defaultdict
    N, M = [int(i) for i in input().split()]
    aabb = [list(map(int, input().split())) for _ in range(M)]
    d = defaultdict(int)
    for a, b in aabb:
        d[a] += 1
        d[b] += 1
    for i in range(1, N + 1):
        print(d[i])


resolve()

Submission status: Accepted

Solution code:
n,m,*a=open(0).read().split()
for i in range(int(n)):print(a.count(str(i+1)))

Submission status: Accepted

Solution code:
def main():
  n,m = list(map(int,input().split()))
  dic={}
  for i in range(1,n+1):
    dic[i]=0
  for _ in range(m):
    b, c = map(int, input().split())
    dic[b]+=1
    dic[c]+=1
  for i in range(1,n+1):
    print(dic[i])

main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
t=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    t[a-1]+=1
    t[b-1]+=1
for x in t:
  print(x)