AtCoder Beginner Contest 061 - Counting Roads

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-----
4 3
1 2
2 3
1 4

-----Sample Output-----
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.

Source: atcoder | Difficulty: EASY


Solutions:
(N, M) = tuple(map(int, input().split()))
count_road = [0 for _ in range(N + 1)]
for _ in range(M):
	(a, b) = tuple(map(int, input().split()))
	count_road[a] += 1
	count_road[b] += 1
for i in range(1, N + 1):
	print(count_road[i])


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


(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 r in R:
	print(r)


(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
print(*cnt)


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


(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
print(*L[1:], sep='\n')


import numpy as np
(n, m) = map(int, input().split())
ans = np.zeros(n, dtype=int)
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])


import itertools
(n, m) = map(int, input().split())
li = [list(map(int, input().split())) for i in range(m)]
lis = list(itertools.chain.from_iterable(li))
for i in range(1, n + 1):
	print(lis.count(i))


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


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


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


(N, M) = map(int, input().split())
lis = []
for i in range(M):
	lis += map(int, input().split())
for j in range(N):
	print(lis.count(j + 1))


(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))


(N, M) = map(int, input().split())
roads = [int(i) for _ in range(M) for i in input().split()]
for i in range(1, N + 1):
	print(roads.count(i))


(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))


(n, m) = map(int, input().split())
num = []
for i in range(m):
	(a, b) = map(int, input().split())
	num.append(a)
	num.append(b)
for i in range(n):
	print(num.count(i + 1))


(n, m) = map(int, input().split())
ab = []
for i in range(m):
	ab.extend(input().split())
for i in range(n):
	print(ab.count(str(i + 1)))


(n, m) = map(int, input().split())
l = [0] * n
for i in range(m):
	(p, q) = map(int, input().split())
	l[p - 1] += 1
	l[q - 1] += 1
print(*l, sep='\n')


(n, m) = map(int, input().split())
a = sum([input().split() for _ in range(m)], [])
[print(a.count(str(i + 1))) for i in range(n)]


import sys
readline = sys.stdin.readline
(N, M) = map(int, readline().split())
ans = [0] * N
for i in range(M):
	ab = list(map(int, readline().split()))
	for a in ab:
		ans[a - 1] += 1
for a in ans:
	print(a)


(N, M, *A) = map(int, open(0).read().split())
l = [0] * N
for a in A:
	l[a - 1] += 1
for r in l:
	print(r)


(n, m) = map(int, input().split())
l = []
for _ in range(m):
	l += input().split()
for i in range(1, n + 1):
	print(l.count(str(i)))


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


(N, M) = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
WAY = [0] * (N + 1)
for (a, b) in AB:
	WAY[a] += 1
	WAY[b] += 1
print('\n'.join(map(str, WAY[1:])))


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


(N, M) = [int(x) for x in input().split()]
A = []
for i in range(M):
	A += [int(x) for x in input().split()]
for i in range(N):
	print(A.count(i + 1))


(N, M) = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(M)]
d = {i + 1: 0 for i in range(N)}
for i in range(M):
	a = ab[i][0]
	b = ab[i][1]
	d[a] += 1
	d[b] += 1
for i in range(N):
	print(d[i + 1])


(n, m) = map(int, input().split())
c = {i: 0 for i in range(1, n + 1)}
for (a, b) in [list(map(int, input().split())) for i in range(m)]:
	c[a] += 1
	c[b] += 1
print(*c.values(), sep='\n')


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


(N, M) = map(int, input().split())
ab = []
[[ab.append(int(x)) for x in input().split()] for i in range(M)]
[print(ab.count(i)) for i in range(1, N + 1)]


(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])


(n, m) = [int(i) for i in input().split()]
ans = []
for _ in range(m):
	ans += list(input().split())
for i in range(n):
	print(ans.count(str(i + 1)))


(N, M) = list(map(int, input().split()))
a_s = []
b_s = []
for i in range(M):
	(a, b) = list(map(int, input().split()))
	a_s.append(a)
	b_s.append(b)
for i in range(1, N + 1):
	print(a_s.count(i) + b_s.count(i))


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


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


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


(N, M) = map(int, input().split())
road_list = []
for i in range(M):
	road_list.append(list(map(int, input().split())))
road_dict = {}
for road in road_list:
	first_city = road[0]
	second_city = road[1]
	first_city_road_list = road_dict.get(first_city, [])
	first_city_road_list.append(second_city)
	road_dict[first_city] = first_city_road_list
	second_city_road_list = road_dict.get(second_city, [])
	second_city_road_list.append(first_city)
	road_dict[second_city] = second_city_road_list
for i in range(1, N + 1):
	city_road_list = road_dict.get(i, [])
	road_num = len(city_road_list) if city_road_list != [] else 0
	print(road_num)


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


(n, m) = map(int, input().split())
l = []
for i in range(m):
	(x, y) = map(int, input().split())
	l.append(x)
	l.append(y)
for i in range(n):
	print(l.count(i + 1))


(n, m) = [int(i) for i in input().split()]
r = []
for i in range(m):
	r += [int(i) for i in input().split()]
for i in range(n):
	print(r.count(i + 1))


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


(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 r in c:
	print(r)


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


(N, M) = map(int, input().split())
nums = [0] * (N + 1)
for _ in range(M):
	(a, b) = map(int, input().split())
	nums[a] += 1
	nums[b] += 1
print(*nums[1:], sep='\n')


(n, m) = map(int, input().split())
l = []
for i in range(m):
	(a, b) = map(int, input().split())
	l.append(a)
	l.append(b)
for i in range(n):
	t = i + 1
	ans = l.count(t)
	print(ans)


(n, m) = map(int, input().split())
graph = [[] for i in range(n + 1)]
for i in range(m):
	(a, b) = map(int, input().split())
	graph[a].append(b)
	graph[b].append(a)
for i in range(n):
	print(len(graph[i + 1]))


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


(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 e in c:
	print(e)


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


(N, M) = list(map(int, input().split()))
data = [[] for _ in range(N + 1)]
for i in range(M):
	(x, y) = list(map(int, input().split()))
	data[x].append(y)
	data[y].append(x)
for i in range(1, N + 1):
	print(len(data[i]))


(N, M) = map(int, input().split())
city = [0] * N
for i in range(M):
	road = list(map(int, input().split()))
	for j in road:
		city[j - 1] += 1
for i in city:
	print(i)


(N, M) = map(int, input().split())
l = []
for i in range(M):
	l += list(map(int, input().split()))
for i in range(N):
	print(l.count(i + 1))


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


(n, m) = map(int, input().split())
s = ''
for i in range(0, m):
	s += ' ' + input() + ' '
[print(s.count(' ' + str(i) + ' ')) for i in range(1, n + 1)]


(N, M) = map(int, input().split())
lst = []
for _ in range(M):
	lst += input().split()
for i in range(1, N + 1):
	print(lst.count(str(i)))


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


(n, m) = map(int, input().split())
data = [input().split() for i in range(m)]
for i in range(1, n + 1):
	count = 0
	for j in range(m):
		if int(data[j][0]) == i or int(data[j][1]) == i:
			count += 1
	print(count)


(n, m) = map(int, input().split())
l = [0] * n
for i in range(0, m):
	for j in list(map(int, input().split())):
		l[j - 1] += 1
for i in range(0, n):
	print(l[i])


(n, m) = map(int, input().split())
road = [list(map(int, input().split())) for _ in range(m)]
cnt = [0] * n
for i in road:
	cnt[i[0] - 1] += 1
	cnt[i[1] - 1] += 1
for j in range(n):
	print(cnt[j])


(N, M) = map(int, input().split())
l = [0] * N
for i in range(M):
	(a, b) = map(int, input().split())
	l[a - 1] += 1
	l[b - 1] += 1
print(*l, sep='\n')


I = lambda : map(int, input().split())
(N, M) = I()
r = range(N)
m = {i: 0 for i in r}
for _ in [0] * M:
	(a, b) = I()
	m[a - 1] += 1
	m[b - 1] += 1
for i in r:
	print(m[i])


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


(n, m) = map(int, input().split())
x = [0] * n
for i in range(m):
	(y, z) = map(int, input().split())
	x[y - 1] += 1
	x[z - 1] += 1
for i in range(n):
	print(x[i])


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


(n, _, *r) = map(int, open(0).read().split())
print(*map(r.count, range(1, n + 1)))


(N, M, *A) = map(int, open(0).read().split())
l = [0] * N
for (a, b) in zip(A[::2], A[1::2]):
	l[a - 1] += 1
	l[b - 1] += 1
for r in l:
	print(r)


(N, M) = map(int, input().split())
R = []
for _ in range(M):
	R += list(map(int, input().split()))
for i in range(1, N + 1):
	print(R.count(i))


(N, M) = map(int, input().split())
c = []
for _ in range(M):
	a = input().split()
	c.extend(a)
for i in range(1, N + 1):
	print(c.count(str(i)))


(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])


(n, _, *r) = map(int, open(0).read().split())
for i in range(n):
	print(r.count(-~i))


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


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


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


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


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


from typing import List

def answer(n: int, m: int, ab_s: List[List[int]]) -> List[int]:
	roads = [0 for _ in range(n)]
	for ab in ab_s:
		(a, b) = ab
		roads[a - 1] += 1
		roads[b - 1] += 1
	return roads

def main():
	(n, m) = map(int, input().split())
	ab_s = [list(map(int, input().split())) for _ in range(m)]
	for i in answer(n, m, ab_s):
		print(i)

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ans = []
for i in range(n):
	cnt = 0
	for j in range(m):
		if ab[j][0] == i + 1 or ab[j][1] == i + 1:
			cnt += 1
	ans.append(cnt)
for k in range(n):
	print(ans[k])


import itertools
(N, M) = list(map(int, input().split()))
res = []
for i in range(M):
	ab = list(map(int, input().split()))
	res.append(ab)
res = list(itertools.chain.from_iterable(res))
for i in range(N):
	print(res.count(i + 1))


(N, M) = map(int, input().split())
roads = []
for i in range(M):
	roads.extend(input().split())
for i in range(N):
	print(roads.count(str(i + 1)))


lst1 = input().split()
N = int(lst1[0])
M = int(lst1[1])
lst2 = []
for i in range(M):
	lst2.append(input().split())
lst3 = []
for i in range(N):
	lst3.append(0)
for i in range(M):
	for j in range(2):
		lst3[int(lst2[i][j]) - 1] += 1
for i in range(N):
	print(lst3[i])


(n, m) = map(int, input().split())
a = eval(','.join((input().replace(' ', ',') for i in [0] * m)))
for i in range(n):
	print(a.count(i + 1))


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


(N, M) = map(int, input().split())
Br = [None] * (2 * M)
for i in range(M):
	(Br[2 * i], Br[2 * i + 1]) = map(int, input().split())
for i in range(N):
	print(Br.count(i + 1))


((n, m), *r) = [[*map(int, i.split())] for i in open(0)]
for i in range(1, n + 1):
	print(sum(r, []).count(i))


(n, m) = map(int, input().split())
N = list(range(1, n + 1))
D = dict.fromkeys(N, 0)
for _ in range(m):
	R = list(map(int, input().split()))
	for r in R:
		D[r] += 1
for d in D.values():
	print(d)


(n, m) = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(m):
	(a, b) = list(map(int, input().split()))
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
for nd in g:
	print(len(nd))


(N, M, *cnt) = open(0).read().split()
from collections import Counter
cnt = Counter(cnt)
for i in range(1, int(N) + 1):
	print(cnt[str(i)])


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


(N, M) = list(map(int, input().split()))
li = []
for _ in range(M):
	li += input().split()
for i in range(1, N + 1):
	print(li.count(str(i)))


(c, r) = [int(x) for x in input().split()]
total = [0] * c
for i in range(r):
	(f, s) = [int(x) for x in input().split()]
	total[f - 1] += 1
	total[s - 1] += 1
for number in total:
	print(number)


(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)


(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')


from collections import Counter
(N, M, *X) = map(int, open(0).read().split())
C = Counter(X)
for i in range(1, N + 1):
	print(C[i] if i in C else 0)


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


(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))


def main():
	import numpy as np
	(N, M) = list(map(int, input().split()))
	ab = np.array([list(map(int, input().split())) for _ in range(M)])
	for i in range(1, N + 1):
		print(np.count_nonzero(ab == i))
main()


(N, M) = map(int, input().split())
a = sum([list(map(int, input().split())) for _ in range(M)], [])
for n in range(1, N + 1):
	print(a.count(n))


(n, m) = list(map(int, input().split()))
al = []
bl = []
for i in range(m):
	(a, b) = list(map(int, input().split()))
	al.append(a)
	bl.append(b)
for i in range(1, n + 1):
	print(al.count(i) + bl.count(i))


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


(a, b) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(b)]
for j in range(1, a + 1):
	print(sum((1 for i in l if i[0] == j or i[1] == j)))


(a, b) = map(int, input().split())
p = [0] * a
for i in range(b):
	(c, d) = map(int, input().split())
	p[c - 1] += 1
	p[d - 1] += 1
for i in range(a):
	print(p[i])


(N, M, *roads) = map(int, open(0).read().split())
for i in range(1, N + 1):
	print(roads.count(i))


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


(n, m) = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
	(a, b) = map(int, input().split())
	edge[a - 1].append(b - 1)
	edge[b - 1].append(a - 1)
print('\n'.join(list(map(lambda x: str(len(x)), edge))))


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


import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce
rr = lambda : sys.stdin.readline().rstrip()
rs = lambda : sys.stdin.readline().split()
ri = lambda : int(sys.stdin.readline())
rm = lambda : list(map(int, sys.stdin.readline().split()))
rl = lambda : list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10 ** 9 + 7
(n, m) = rm()
li = [[] for _ in range(n)]
for _ in range(m):
	(a, b) = rm()
	a -= 1
	b -= 1
	li[a].append(b)
	li[b].append(a)
for lis in li:
	print(len(lis))


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


(N, M) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
ans = [0 for _ in range(N)]
n = 1
while True:
	for i in range(M):
		for j in range(2):
			if n == ab[i][j]:
				ans[n - 1] += 1
	if n == N:
		break
	n += 1
for i in range(N):
	print(ans[i])


(n, m) = map(int, input().split())
a = []
for _ in [0] * m:
	a += input().split()
for x in range(n):
	print(a.count(str(-~x)))


(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
for an in ans:
	print(an)


(t, l) = map(int, input().split())
li = [0 for i in range(t)]
for i in range(l):
	(a, b) = map(int, input().split())
	li[a - 1] += 1
	li[b - 1] += 1
print(*li, sep='\n')


from collections import defaultdict
(n, m) = map(int, input().split())
ans = 0
route = [[0] * (n + 1) for i in range(n + 1)]
for i in range(m):
	(f, t) = map(int, input().split())
	route[f][t] += 1
	route[t][f] += 1
for i in range(1, n + 1):
	print(sum(route[i]))


(n, m) = list(map(int, input().split()))
a_s = []
b_s = []
for i in range(m):
	(a, b) = list(map(int, input().split()))
	a_s.append(a)
	b_s.append(b)
for i in range(1, n + 1):
	print(a_s.count(i) + b_s.count(i))


(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))


(n, m) = map(int, input().split())
road_list = []
for _ in range(m):
	(a, b) = input().split()
	road_list.append(a)
	road_list.append(b)
for i in range(1, n + 1):
	print(road_list.count(str(i)))


(n, m) = map(int, input().split())
edges = [tuple(map(int, input().split())) for _ in range(m)]
c = [[] for _ in range(n + 1)]
for (a, b) in edges:
	c[a].append(b)
	c[b].append(a)
for i in range(1, n + 1):
	print(len(c[i]))


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


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


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


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


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


(N, _, *R) = open(0).read().split()
for i in range(int(N)):
	print(R.count(str(i + 1)))


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


(n, m) = [int(x) for x in input().split()]
r = [input() for _ in range(m)]
r = ' '.join(r).split()
for i in range(1, n + 1):
	print(r.count(str(i)))


(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 j in range(n):
	print(A.count(j + 1) + B.count(j + 1))


import sys
input = sys.stdin.readline

def main2():
	numbers = []
	(n, m) = map(int, input().split())
	numbers = [list(map(int, input().split())) for _ in range(m)]
	dp = [0] * n
	for number in numbers:
		for n in number:
			dp[n - 1] += 1
	for ans in dp:
		print(ans)

def main():
	numbers = []
	(n, m) = map(int, input().split())
	numbers = [list(map(int, input().split())) for _ in range(m)]
	dp = {}
	for number in numbers:
		for n in number:
			if n not in dp:
				dp[n] = 1
			else:
				dp[n] += 1
	print(dp)
	for i in range(1, len(dp) + 1):
		print(dp[i])

def __starting_point():
	main2()
__starting_point()


(n, m) = map(int, input().split())
j = []
for x in range(m):
	j += list(map(int, input().split()))
for x in range(1, n + 1):
	print(j.count(x))


(a, b) = map(int, input().split())
L = []
for i in range(1, b + 1):
	L += [int(x) for x in input().split()]
for j in range(1, a + 1):
	print(L.count(j))


(n, m) = map(int, input().split())
s = []
N = [0 for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	s.append([a, b])
	N[a - 1] += 1
	N[b - 1] += 1
for j in range(n):
	print(N[j])


nm = list(map(int, input().split()))
(n, m) = (nm[0], nm[1])
ab_list = [list(map(int, input().split())) for _ in range(m)]
results = dict([(i, 0) for i in range(1, n + 1)])
for ab in ab_list:
	results[ab[0]] += 1
	results[ab[1]] += 1
for i in range(1, n + 1):
	print(results[i])


from collections import Counter
(n, m) = map(int, input().split())
l = []
for i in range(m):
	lis = list(map(int, input().split()))
	l += lis
l = Counter(l)
for i in range(1, n + 1):
	print(l[i])


(N, M) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(M)]
for i in range(1, N + 1):
	print(sum(ab, []).count(i))


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


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


(n, m) = list(map(int, input().split()))
arr = [0] * n
for _ in range(m):
	(x, y) = list(map(int, input().split()))
	arr[x - 1] += 1
	arr[y - 1] += 1
for ele in arr:
	print(ele)


(n, m) = list(map(int, input().split()))
AB = [[] for _ in range(n)]
for i in range(m):
	(a, b) = [int(x) - 1 for x in input().split()]
	AB[a].append(b)
	AB[b].append(a)
for i in range(n):
	print(len(AB[i]))


(n, m) = map(int, input().split())
c = [0] * n
for _ in [0] * m:
	(a, b) = map(int, input().split())
	c[a - 1] += 1
	c[b - 1] += 1
print(*c, sep='\n')


(N, M) = map(int, input().split())
a = sorted([i for _ in range(M) for i in input().split()])
for i in range(1, N + 1):
	print(a.count(str(i)))


(N, M) = map(int, input().split())
x = [0] * (N + 1)
for i in range(M):
	(a, b) = map(int, input().split())
	for j in range(1, N + 1):
		if a == j or b == j:
			x[j] += 1
for i in range(1, N + 1):
	print(x[i])


(n, m) = map(int, input().split())
l = list()
[l.extend(input().split()) for i in range(0, m)]
[print(l.count(str(i))) for i in range(1, n + 1)]


(N, M) = map(int, input().split())
l = []
for m in range(M):
	l += input().split()
for n in range(N):
	print(l.count(str(n + 1)))


def actual(N, M, A, B):
	AB = A + B
	counts = [AB.count(i) for i in range(1, N + 1)]
	return '\n'.join(map(str, counts))
(N, M) = list(map(int, input().split()))
(A, B) = ([], [])
for _ in range(M):
	(a, b) = list(map(int, input().split()))
	A.append(a)
	B.append(b)
print(actual(N, M, A, B))


(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])


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