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:
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    d = defaultdict(lambda: 0)
    N, M = map(int, input().split())
    for _ in range(M):
        a, b = map(int, input().split())
        d[a] += 1
        d[b] += 1

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(1,N+1):
  print(numbers.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 a in ans:
    print(a)

Submission status: Accepted

Solution code:
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

for a in count:
    print(a)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
R = [tuple(map(int, input().split())) for _ in range(M)]
C = [[] for _ in range(N)]
for r in R:
	C[r[0]-1].append(r[1]-1)
	C[r[1]-1].append(r[0]-1)
for c in C:
	print(len(c))

Submission status: Accepted

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

Submission status: Accepted

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

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

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:
from numpy import zeros
n, m = map(int, input().split())
ci = zeros(n)
for i in range(m):
    f, t = map(int, input().split())
    ci[f-1] += 1
    ci[t-1] += 1
for i in range(n):
    print(int(ci[i]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append([0]*n)
    
for _ in range(m):
    i, j = map(int, input().split())
    a[i-1][j-1] += 1
    a[j-1][i-1] += 1
for a_ in a:
    print(sum(a_))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans=[0for i in range(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:
# coding: utf-8
# Your code here!
n,m, = map(int,input().split())
list = [] 
for i in range(n+1):
    list.append(0)
for i in range(m):
    load1,load2 = map(int,input().split())
    list[load1] = list[load1]+1
    list[load2] = list[load2]+1
for i in range(1,n+1):
    print(list[i])

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
a,b,c = LI()
if a <= c <= b:
    print("Yes")
else:
    print("No")
"""
#B
n,m = LI()
d = [0 for i in range(n+1)]
for i in range(m):
    a,b = LI()
    d[a] += 1
    d[b] += 1
for i in range(1,n+1):
    print(d[i])
#C

#D
"""
def bellman_ford(start):
    dist = [float("inf") for i in range(n)]
    dist[start] = 0
    for i in range(n-1):
        update = False
        for j, k, l in adj:
                if dist[k] > dist[j] + l:
                    dist[k] = dist[j] + l
                    update = True
        if not update:
            break
    negative = [False for i in range(n)]
    for j, k, l in adj:
        if dist[k] > dist[j] + l:
            dist[k] = dist[j] + l
            negative[k] = True
    return dist,negative[n-1]
n,m = LI()
adj = []
for i in range(m):
    a,b,c = LI()
    a -= 1
    b -= 1
    adj.append([a,b,-c])
d,ne = bellman_ford(0)
if ne:
    print("inf")
else:
    print(-d[-1])
"""

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a + b)

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

Submission status: Accepted

Solution code:
def counting_roads(N: int, M: int, roads: list)->list:
    d = {i: 0 for i in range(N)}
    for u, v in roads:
        d[u-1] += 1
        d[v-1] += 1

    return d.values()


if __name__ == "__main__":
    M = 0
    N, M = map(int, input().split())
    roads = [tuple(map(int, input().split())) for _ in range(M)]
    ans = counting_roads(N, M, roads)
    print('\n'.join(map(str, ans)))

Submission status: Accepted

Solution code:
import collections
N,M=map(int,input().split())
road=[]
for i in range(M):
    road.extend([int(i) for i in input().split()])
roads=collections.Counter(road)
[print(roads[i+1]) for i in range(N)]

Submission status: Accepted

Solution code:
n, m = [int(_) for _ in input().split()]
ans = [0]*(n+1)

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
city = [0 for i in range(N)]
for i in range(M):
  start, end = map(int, input().split())
  city[start-1] += 1
  city[end-1] += 1

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
bucket = {}
for i in range(N):
  bucket[i] = 0
for m in range(M):
  tempa,tempb = map(int,input().split())
  bucket[tempa-1] += 1
  bucket[tempb-1] += 1
for i in range(N):
  print(bucket[i])

Submission status: Accepted

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

L =[0 for i in range(N)]

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

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

Submission status: Accepted

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

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

[print(result[i]) for i in range(N)]

Submission status: Accepted

Solution code:
from collections import defaultdict
n, m = map(int, input().split())
d = defaultdict(int)
for i in range(m):
    a, b = map(int, input().split())
    d[a] += 1
    d[b] += 1
for i in range(n):
    print(d[i+1])

Submission status: Accepted

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

cs = [0] * N
for a, b in abn:
    cs[a-1] += 1
    cs[b-1] += 1

for c in cs:
    print(c)

Submission status: Accepted

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

for j in range(n):
  a = 0
  for k in range(m):
    a = a + listA[k].count(j+1)
  print(a)

Submission status: Accepted

Solution code:
# 061 B
N,M= map(int,input().split())
f = [0] * (N + 20)
for i in range(M):
    x,y = map(int,input().split())
    f[x]+=1
    f[y]+=1
for i in range(1,N+1):
    print(f[i])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0] * N
for i in range(M):
    ans[ A[i] - 1 ] += 1
    ans[ B[i] - 1 ] += 1

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

Submission status: Accepted

Solution code:
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 k in c:
    print(k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = list(map(int, input().split()))
cities = [0 for i in range(n)]
for i in range(m):
    bridges = list(map(int, input().split()))
    cities = [x+1 if i+1 in bridges else x for i,x in enumerate(cities)]
print("\n".join(list(map(str, cities))))

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_list_of_float():
    return [float(f) for f in input().split()]


def get_list_of_char():
    return list(input().strip())


def get_data(n, order=None, **kwargs):
    if not order:
        order = range(len(kwargs))
    it = iter(order)
    var, fn = zip(*sorted(sorted(kwargs.items()), key=lambda _: next(it)))

    rows = []
    for _ in range(n):
        rows.append(input().split())
    columns = zip(*rows)
    exec("global "+", ".join(var)+"\n"+"\n".join(
        v+"=list(map(fn[{}], data[{}]))".format(i, i)
        for i, v in enumerate(var)),
        globals(),
        {"fn": list(fn), "data": list(columns)}
    )
    return


# inputs
N, M = 0, 0
A, B = [], []


def set_inputs():
    global N, M, A, B
    N, M = get_list_of_int()
    get_data(M, A=int, B=int)
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    s = "".join(list(map(lambda x: chr(ord("A") + x), A + B)))
    for i in range(N):
        print(s.count(chr(ord("A") + i + 1)))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def getlist():
    return list(map(int, input().split()))

n,m = getlist()

cities = [0 for i in range(n)]
for i in range(m):
    a,b = getlist()
    cities[a-1] += 1
    cities[b-1] += 1

print("\n".join(list(map(str, cities))))

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

for a in ans:
  print(a)

Submission status: Accepted

Solution code:
#B問題
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(M)]
ans=[0 for i in range(N)]
for i in range(M):
    A=ab[i][0]-1
    B=ab[i][1]-1
    ans[A]+=1
    ans[B]+=1
for i in range(N):
    print(ans[i])

Submission status: Accepted

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

l = [list(map(int,input().split())) for i in range(m)]

for i in range(n):
	c = 0
	for j in range(m):
		c += l[j].count(i+1)
		
	print(c)

Submission status: Accepted

Solution code:
from collections import defaultdict
class Graph(object):
    #隣接リストによる有向グラフ
    def __init__(self):
        self.graph = defaultdict(list)
    def __len__(self):
        return len(self.graph)
    def add_edge(self, src, dst):
        self.graph[src].append(dst)
N,M = map(int,input().split())
loapdic = {}
ga = Graph()
for i in range(M):
    a,b = map(int,input().split())
    ga.add_edge(a, b)
    ga.add_edge(b, a)
for n in range(1,N+1):
    print(len(ga.graph[n]))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, n+1):
    ans = 0
    for x, y in bridge:
        if x == i or y == i:
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(M)]
al = []
for a in A:
    al += a

d = defaultdict(int)

for v in al:
    d[v] += 1

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
road = [0] * N
for _ in range(M):
    C,D = map(int,input().split())
    road[C-1] += 1
    road[D-1] += 1
for r in road:
    print(r)

Submission status: Accepted

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

count = [0]*n

for x in e:
    for y in x:
        count[y] += 1

for x in count:
    print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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(1,N+1):
    print(L.count(i))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
alist = [0] * M
blist = [0] * M
for i in range(M):
    alist[i], blist[i] = map(int, input().split())
city = list(range(1,N+1))
judge = [0] * N
count = dict(zip(city,judge))
for a,b in zip(alist,blist):
    count[a] += 1
    count[b] += 1
for c in count:
    print(count[c])

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
n,m = map(int,input().split())
s = [list(map(int,input().split())) for i in range(m)]
t = np.ravel(s)

for i in range(1,n+1):
    print(np.sum(t == i))

Submission status: Accepted

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

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

for i in count:
    print(i)

Submission status: Accepted

Solution code:
from itertools import chain
n,m = map(int,input().split())
ab_list = [list(map(int, input().split())) for _ in range(m)]
tmp_list = sorted(list(chain(*ab_list)))
tmp_dic = {}
for i in range(1,n+1):
    tmp_dic[i]=0
for val in tmp_list:
    tmp_dic[val] += 1
for k,v in tmp_dic.items():
    print(v)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
L = [[int (y) for y in input().split()] for _ in range(M)]
L = sum(L, [])

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

Submission status: Accepted

Solution code:
import numpy as np

N, M = [int(x) for x in input().split()]
L = [[int (y) for y in input().split()] for _ in range(M)]
L = sum(L, [])

for i in np.arange(1, N+1):
    print(L.count(i))

Submission status: Accepted

Solution code:
N, M = [ int(x) for x in input().split() ]
ab_s = [ [ int(x) for x in input().split() ] for _ in range(M) ]

ans = []
for i in range(N):
    n = 0
    for j in range(M):
        a, b = ab_s[j]
        if a == (i + 1) or b == (i + 1):
            n += 1
    ans.append(n)

print("\n".join(map(str, ans)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
n,m=map(int,input().split())
k = []
[k.append(z[0]) for _ in range(m)  for z in itertools.permutations(input().split())]
for nn in range(1, n+1):
  print(k.count(str(nn)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# abc061_b

"""
Counting Roads
"""

def answer():
    """
    答えをN行で出力する。
    """
    N, M = map(int, input().split())
    load = []
    for _ in range(M):
        load += list(map(int, input().split()))

    # 各都市の出現回数を2で割ったものを出力する。
    for i in range(1, N+1):
        print(load.count(i))


def main():
    """
    処理を実行する。
    """
    answer()

if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

countDic = {}

for nn in range(n+1):
	countDic[nn] = 0
	
for ab in abm:
	countDic[ab[0]] += 1
	countDic[ab[1]] += 1

ks = countDic.keys()
ks = sorted(ks)[1:]

for k in ks:
	print(countDic[k])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
es = [[] for _ in range(n)]
for _ in range(m):
  s, t = map(int, input().split())
  es[s-1].append(t-1)
  es[t-1].append(s-1)
for i in range(n):
  print(len(es[i]))

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M = map(int, input().split())
adj = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    adj[a].append(b)
    adj[b].append(a)

for l in adj:
    print(len(l))

Submission status: Accepted

Solution code:
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(1,n+1):
    print(L.count(i))

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

for i in range(n):
    print(ans[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 ans:
    print(i)

Submission status: Accepted

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

# for road in roads:
#     if road[0] > road[1]:
#         road[0], road[1] = road[1], road[0]

for i in range(1, n + 1):
    counter = 0
    for road in roads:
        if i in road:
            counter += 1
    print(counter)

Submission status: Accepted

Solution code:
""" AtCoder """

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

ans = [0 for _ in range(N)]

for i in range(M):
    ans[ab[i][0]-1] += 1
    ans[ab[i][1]-1] += 1

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

Submission status: Accepted

Solution code:
n,m=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(m):
    AA,BB=[int(i) for i in input().split()]
    a.append(AA)
    b.append(BB)
for i in range(n):
    cnt=0
    cnt=a.count(i+1)+b.count(i+1)
    print(cnt)

Submission status: Accepted

Solution code:
N,M = map(int,input().split()) 
dic = {}
for i in range(N):
  tmp = str(i+1)
  dic[tmp] = 0

for i in range(M):
  s = input().split()
  a = s[0]
  b = s[1]
  dic[a] += 1
  dic[b] += 1
   
for i in range(N):
  tmp = str(i+1)
  print(dic[tmp])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a,b=[],[]                       #リストを二つ作ってcountで数えればOK
for i in range(M):
  x,y=input().split()
  a.append(x)
  b.append(y)
for j in range(1,N+1):          #N行出力なのでforとprintで回す
  e1=a.count("{}".format(j))
  e2=b.count("{}".format(j))
  print(e1+e2)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a_list = []
b_list = []

for i in range(m):
    a, b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)

for i in range(1,n+1):
    cnt = 0
    for j in range(m):
        if a_list[j] == i or b_list[j] == i:
            cnt += 1
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

N, M = list(map(int, input().split()))
ab = []

for i in range(M):
    ab.extend(list(map(int, input().split())))
ab = Counter(ab)

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

Submission status: Accepted

Solution code:

N, M = map(int, input().split())
cities = {}
for i in range(1, N+1):
    cities[i] = 0
for _ in range(0, M):
    a, b = map(int, input().split())
    cities[a] += 1
    cities[b] += 1
# 都市をkeyにしたdictを作って、その内容をインクリしていく?
for i in range(1, N+1):
    print (cities[i])

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("yes")
    else:print("no")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())


#n = ip()                              #入力整数1つ
n,m= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
#n,a,b,c= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(h)]
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
s = [0 for i in range(n+1)]
for i in range(m):
    a,b = (int(i) for i in input().split())
    s[a]+=1
    s[b]+=1
for i in range(1,n+1):
    print(s[i])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a = [input().split() for j in range(1) for i in range(m)]
b = sum(a, [])

L = []

for i in range(1, n+1):
    L.append(b.count(str(i)))

for i in L:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
x = [ list(map(int, input().split())) for i in range(M)]
bucket = {str(i):0 for i in range(1, N+1)}
for i in x:
    for p in i:
        bucket[str(p)] += 1
for i in range(1, N+1):
    print(bucket[str(i)])

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
roads = [list(map(lambda x:int(x)-1, input().split())) for _ in range(m)]

arr = [0]*n
for r in roads:
    arr[r[0]] +=1
    arr[r[1]] +=1

for a in arr:
    print(a)

Submission status: Accepted

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

Submission status: Accepted

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

counters = [0 for i in range(N)]

for i in range(len(_input)):
    counters[_input[i][0]-1] += 1
    counters[_input[i][1]-1] += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
tree= [[] for i in range(n)]
for i in range(m):
  tmp1,tmp2 = map(int,input().split())
  tree[tmp1-1].append(tmp2-1)
  tree[tmp2-1].append(tmp1-1)
for i in range(n):
  print(len(tree[i]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
d = {i:0 for i in range(n)}
for a, b in ab:
    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())
a=[]
b=[]
for i in range(m):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
for i in range(m):
    a += 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())
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
a = [None for i in range(M)]
b = [None for i in range(M)]

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

for i in range(N):
  num = 0
  for j in range(M):
    if a[j] == i or b[j] == i:
      num += 1
  print(num)

Submission status: Accepted

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

for i in range(1, len(c)):
    print(c[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

[print(x) for x in ans]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

l = [0] * N

for i in range(M):
    # 0-indexed
    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:
[n,m] = [int(i) for i in input().split()]
ab = []
dic = {}
for i in range(m):
  ab.append([int(j) for j in input().split()])

for i in range(m):
  if ab[i][0] in dic.keys():
    dic[ab[i][0]] += 1
  else:
    dic[ab[i][0]] = 1
    
  if  ab[i][1] in dic.keys():
    dic[ab[i][1]] += 1
  else:
    dic[ab[i][1]] = 1
    
for i in range(n):
  if i+1 in dic.keys():
    print(dic[i+1])
  else:
    print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict
n,m=map(int,input().split())
d=defaultdict(list)
for s in range(m):
  a,b=map(int,input().split())
  d[a].append(b)
  d[b].append(a)
for s in range(1,n+1):
  print(len(d[s]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 i in range(n):
    print(A[i])

Submission status: Accepted

Solution code:
from itertools import chain
N,M=map(int,input().split())
roads=[list(map(int,input().split())) for _ in range(M)]
roads=list(chain.from_iterable(roads))
for i in range(1,N+1):
    print(roads.count(i))

Submission status: Accepted

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