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:
n, m = map(int, input().split())
road = [0]*n

for _ 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:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n,m=MI()
    deg=[0]*n
    for _ in range(m):
        a,b=MI1()
        deg[a]+=1
        deg[b]+=1
    for d in deg:
        print(d)

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def solve(inp):
    (N, M) = map(int, inp.readline().split(' '))
    AB = [list(map(int, inp.readline().split(' '))) for i in range(M)]

    roads = [0 for i in range(N)]
    for ab in AB:
        roads[ab[0] - 1] += 1
        roads[ab[1] - 1] += 1

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

    return ""


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

n,m=map(int, input().split())
ab = ["" for _ in range(m)]

for i in range(m):
    ab[i] = list(map(int, input().split()))
#print(ab)

for i in range(1, n+1):
#    print("i",i)
    count = 0
    for j in range(m):
#        print("j",j)
        if i in ab[j]:
            count += 1
    print(count)

Submission status: Accepted

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

ans = dict()
for i in range(1, N+1):
    ans[i] = 0

for i in range(M):
    a, b = map(int, input().split())
    if a in ans:
        ans[a] += 1
    if b in ans:
        ans[b] += 1
        
ans = sorted(ans.items(), key=lambda x:x[0])
for k, v in ans:
    print(v)

Submission status: Accepted

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

for i in range(1,n+1):
    cnt = 0
    for j in range(m):
        cnt += x[j].count(i)
    lst.append(cnt)

for i in range(n):
    print(lst[i])

Submission status: Accepted

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

for _ in range(N):
    V.append(0)

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

for node in range(N):
    print(V[node])

Submission status: Accepted

Solution code:
listanm = []

n,m = map(int,input().split())

for x in range(n):
    listanm.append(0)

for c in range(m):
    a,b = map(int,input().split())
    listanm[a-1]+=1
    listanm[b-1]+=1
for g in listanm:
    print (g)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 i in range(N):
    print(L[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 ans:
    print(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
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
from collections import Counter
n,m=map(int,input().split())
L=[0]*(2*m)
for i in range(m):
    L[2*i],L[2*i+1]=map(int,input().split())
s=Counter(L)
for i in range(n):
    print(s[i+1])

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(n):
    print(l.count(i+1))

Submission status: Accepted

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

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

for i in range(1, N+1):
  print(len(graph[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())
for j in range(n):
  print(a.count(j+1)+b.count(j+1))

Submission status: Accepted

Solution code:
from collections import Counter
def get(S):
    return list(map(S, input().split()))

N, M = get(int)
roads = Counter()

for i in range(M):
    a, b = get(int)
    roads[a] += 1
    roads[b] += 1

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = []
for i in range(m):
  l.extend(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())
result = [0]*N
for i in range(M):
  a,b = map(int,input().split())
  result[a-1] += 1
  result[b-1] += 1
for j in range(N):
  print(result[j])

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(lambda x:int(x)-1, input().split())
	G[a].append(b)
	G[b].append(a)

for i in range(N):
	print(len(G[i]))

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
from collections import Counter
N, M = [int(i) for i in input().split()]
L = [list(map(int, input().split())) for i in range(M)]
LL = sum(L, [])

cou = Counter(LL)

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

Submission status: Accepted

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

res = {}
for i in range(1, N+1):
    res[i] = 0

# for x, y in roads:
#     res[x] += 1
#     res[y] += 1


for i in range(M):
    x, y = list(map(int, input().split()))
    res[x] += 1
    res[y] += 1

for val in res.values():
    print(val)

Submission status: Accepted

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

res = {}
for i in range(1, N+1):
    res[i] = 0

for x, y in roads:
    res[x] += 1
    res[y] += 1

for val in res.values():
    print(val)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
from collections import defaultdict
dic = defaultdict(int)

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

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

Submission status: Accepted

Solution code:
import sys
n,m = map(int, sys.stdin.readline().split())

l = [0] * n

for i in range(m):
    a, b = map(int, sys.stdin.readline().split())
    l[a-1] += 1
    l[b-1] +=1

for i in l:
    print(i)

Submission status: Accepted

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

for i in range(M):
    a, b = input().split()
    A.append(int(a))
    B.append(int(b))

for i in range(1, N + 1):
    count = 0
    for j in range(M):
        if A[j] == i or B[j] == i:
            count += 1
    print(count)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

n, m, *r = map(int, sys.stdin.read().split())

def main():
    c = Counter(r)
    for v in range(1, n+1):
        yield c.get(v, 0)

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

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

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

Submission status: Accepted

Solution code:
import sys
bbn=1000000007
	
#+++++
		
def main():
	n, m = map(int, input().split())
	ll=[0]*n
	for i in range(m):
		a, b = map(int, input().split())
		ll[a-1] += 1
		ll[b-1] += 1
	
	for v in ll:
		print(v)
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

for i in range(m):
    ai,bi = [int(i) for i in input().split()]
    graph[ai-1] += 1
    graph[bi-1] += 1
    
for i in range(n):
    print(graph[i])

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
load_info = {i:[] for i in range(1, n+1)}

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

for n_i in range(1, n+1):
  print(len(load_info[n_i]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

dp = [[0 for i in range(N)] for j in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    dp[a-1][b-1] += 1
    dp[b-1][a-1] += 1
    
for i in range(N):
    print(sum(dp[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 a in ans:
    print(a)

Submission status: Accepted

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

from collections import defaultdict
d = defaultdict(list)
for i in range(len(ab)):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    d[a].append(b)
    d[b].append(a)

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

Submission status: Accepted

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

for i in range(N):
  dic[i+1] = 0

for i in range(M):
  a,b = map(int,input().split())
  dic[a] += 1
  dic[b] += 1
output = dic.values()
for item in output:
  print(item)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
pairs = []
for i in range(m):
  pair = list(map(int,input().split()))
  pairs.append(pair)
answer = {}
count = 0
for j in range(1,n+1):
  count = 0
  for k in range(m):
    if pairs[k][0] == j or pairs[k][1] == j:
      count += 1
  print(count)

Submission status: Accepted

Solution code:


def main()->None:
    N, M = map(int, input().split())
    range_M = range(M)
    ab = []
    for i in range_M:
        a, b = map(int, input().split())
        ab.append(a)
        ab.append(b)
    range_N = range(N)
    for i in range_N:
        print(ab.count(i+1))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ls_ans = [0]*n

for i in range(n):
    for j in range(m):
        if i+1 in ls_ab[j]:
            ls_ans[i] += 1

for k in range(n):
    print(ls_ans[k])

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(n):
    k=0
    for j in range(2*m):
        if i+1==l[j]:
            k+=1
    print(k)

Submission status: Accepted

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


for i in range(1, n+1):
    ans = 0
    for j in street:
        ans += j.count(i)
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    N, M, *AB = map(int, open(0).read().split())
    cnt = defaultdict(int)
    for a, b in zip(*[iter(AB)] * 2):
        cnt[a] += 1
        cnt[b] += 1
    ans = []
    for i in range(1, N + 1):
        ans.append(cnt[i])
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
roads = [0] * n
[exec("roads[%d] += 1; roads[%d] += 1" % tuple(map(lambda c: int(c) - 1, input().split()))) for _ in range(m)]
print(*roads, sep="\n", end="")

Submission status: Accepted

Solution code:
NM = list(map(int,input().split()))
N=NM[0]
M=NM[1]
road=[]

x = []
y = []
for i in range(M):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

for j in range(1,N+1):
    road.append(x.count(j)+y.count(j))
    road[j-1]=str(road[j-1])

print('\n'.join(road))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

clst = [lst.count(i) for i in range(1, n + 1)]
print(*clst,sep='\n')

Submission status: Accepted

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

Submission status: Accepted

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

d = []
for i in range(m):
    a, b = map(int, input().split())
    d.append(a)
    d.append(b)
d = sorted(d)
for i in range(1, n + 1):
  count = 0
  for j in range(len(d)):
    if d[j] == i:
      count += 1
  print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = [0 for i in range(N)]
for i in range(M):
  x,y = map(int,input().split())
  ab.append(x)
  ab.append(y)

for i in range(N):
  cnt[i] = ab.count(i+1)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
##### 解けた #####

N,M=list(map(int,input().split(" ")))
T=[0]*N # 都市

# 各道路について足してゆく
for _ in range(M):
    a,b=list(map(int,input().split(" ")))

    T[a-1]+=1
    T[b-1]+=1

# 各都市について出力
for t in T:
    print(t)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

lin = [0]*n

for i in li:
    lin[i[0]-1] +=1
    lin[i[1]-1] += 1

for i in lin:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

#print(l)

#2次元のリストを1次元にする。
l = sum(l,[])

#print(l)

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

Submission status: Accepted

Solution code:
N,M = (int(i) for i in input().split())
roads = []
for i in range(M):
    X,Y = (int(i) for i in input().split())
    roads.append(X)
    roads.append(Y)
    
for i in range(N):
    ans = roads.count(i+1)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = [0 for i in range(n)]
for _ 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 = map(int, input().split())
towns = [0] * N
for m in range(M):
  a, b = map(int, input().split())
  towns[a - 1] += 1
  towns[b - 1] += 1

for t in towns:
  print(t)

Submission status: Accepted

Solution code:
# atcoder : python3 (3.4.3)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9+7

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

Ans = [0]*N
for a,b in AB:
    Ans[a-1] += 1
    Ans[b-1] += 1

for ans in Ans:
    print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
dic = {}
for i in range(1,N+1):
    dic[i] = 0
for i in range(M):
    a,b = map(int,input().split())
    dic[a] += 1
    dic[b] += 1
for key,value in dic.items():
    print(value)

Submission status: Accepted

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

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

for i in road_list:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
graph = [[] for _ 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(1, N+1):
    print(len(graph[i]))

Submission status: Accepted

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

town = [0 for i in range(n)]

for i in range(len(ab)):
    x, y = ab[i]
    town[x - 1] += 1
    town[y - 1] += 1

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

Submission status: Accepted

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

for town in towns:
    print(town)

Submission status: Accepted

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

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())
loute = a + b
for i in range(n) :
    print(loute.count(i + 1))

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)
    
B = [0 for _ in range(N)]
for i in range(2*M):
    B[L[i]-1] = B[L[i]-1] + 1

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

Submission status: Accepted

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

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 j in range(m):
    ans[a[j]-1]+=1
    ans[b[j]-1]+=1
#print(ans)
for k in range(n):
    print(ans[k])

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:
def main(n, m, a_b):
    road = [list() for n in range(n)]

    for a, b in a_b:
        road[a - 1].append(b)
        road[b - 1].append(a)

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


if __name__ == "__main__":
    n, m = map(int, input().split(" "))
    a_b = [list(map(int, input().split())) for _ in range(m)]

    main(n, m, a_b)

Submission status: Accepted

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

tmp = []
for i in range(M):
    tmp.append(A[i][0])
    tmp.append(A[i][1])

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

path_dict = {n_i:[] for n_i in range(1, n+1)}

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
R = list()
for i in range(N):
  R.append(0)
for i in range(M):
  c1, c2 = map(int, input().split())
  R[c1-1] += 1
  R[c2-1] += 1
for i in range(N):
  print(R[i])

Submission status: Accepted

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

for i in range(M):
  for j in range(2):
    ans[l[i][j]-1] += 1

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

Submission status: Accepted

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

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())
    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:
def examB():
    N, M =LI()
    ans = [0]*N
    for i in range(M):
        a, b = LI()
        ans[a-1] +=1
        ans[b-1] +=1
    for v in ans:
        print(v)

import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 061: B – Counting Roads
n, m = [int(s) for s in input().split()]

a = []
b = []

for _ in range(m):
    tmp = [int(s) for s in input().split()]
    a.append(tmp[0])
    b.append(tmp[1])

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(N, M, inputs):
    roads = list(map(string_to_int, inputs))
    towns = {i+1: [] for i in range(N)}

    for r in roads:
        towns[r[0]].append(r[1])
        towns[r[1]].append(r[0])
    ret = []

    for t in sorted(towns.keys()):
        ret.append(len(towns[t]))
    return ret


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [N, M] = string_to_int(input())
    ret = solve(N, M, inputs(M))
    for r in ret:
        print(r)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = ",".join([str(input().replace(" ",",")) for i in range(M)])
A= A.split(",")
A_list=[int(i) for i in A]
for i in range(1,N+1):
    print(A_list.count(i))

Submission status: Accepted

Solution code:
num = list(map(int, input().split(' ')))
city = num[0]
road = num[1]
city_road = []
for i in range(road):
    city_road.extend(list(map(int, input().split(' '))))

for i in range(city):
    print(city_road.count(i+1))

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

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