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
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
# 約数列挙
def find_divisor(n):
    divisors=[]
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            divisors.append(i)
            if i*i!=n:
                divisors.append(n // i)
    return divisors


# 素因数分解
def prime_factorization(n):
    fact=defaultdict(int)
    for i in range(2, int(sqrt(n)) + 1):
        while n % i == 0:
            n //= i
            fact[i]+=1
    if n!=1:
        fact[n]+=1
    return fact

#mint
class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))

class BigCombination(object):

    def __init__(self, mod: int=10**9+7, max_n: int=10**6):
        fac, inv=[1], []
        fac_append, inv_append=fac.append, inv.append

        for i in range(1, max_n+1):
            fac_append(fac[-1] * i % mod)

        inv_append(pow(fac[-1], mod-2, mod))

        for i in range(max_n, 0, -1):
            inv_append(inv[-1] * i % mod)

        self.mod, self.factorial, self.inverse=mod, fac, inv[::-1]

    def get_combination(self, n, r):
        if n < r:
            return 0
        return self.factorial[n] * self.inverse[r] * self.inverse[n-r] % self.mod

    def get_permutation(self, n, r):
        if n < r:
            return 0
        return self.factorial[n] * self.inverse[n-r] % self.mod

def main():
    N,M,*A=map(int,open(0).read().split())
    C=Counter(A)
    for i in range(1,N+1):
        print(C[i])
    


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

for i in l:
    cnt[i[0]-1]+=1
    cnt[i[1]-1]+=1

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, M = (int(i) for i in input().split())
    c = [0 for i in range(N)]
    for i in range(M):
        a, b = (int(i) for i in input().split())
        c[a-1] += 1
        c[b-1] += 1
    print(*c, sep="\n")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
res = [0] * (N + 1)
for _ in range(M):
  u, v = map(int, input().split())
  res[u] += 1
  res[v] += 1
for r in res[1: ]: print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
try:
    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 k in range(len(dp)):
        print(sum(dp[k]))
except EOFError:
    pass

Submission status: Accepted

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

Submission status: Accepted

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

for country in range(1,N+1):
    count = 0
    for road in R:
        if country in road:
            count += 1
    ans.append(count)

for j in ans:
    print(j)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
G=[list() for _ in range(N+1)]
for i in range(M):
    c,d=map(int,input().split())
    G[c].append(d)
    G[d].append(c)

ans = []
for i in range(1,N+1):
    ans.append(len(G[i]))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for i in result:
    print(i)

Submission status: Accepted

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

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

for ans in ansl:
    print(ans)

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
lst = [[int(x) for x in input().split()] for i in range(M)]
dict = {}
for i in range(1, N + 1):
    dict[i] = 0
for i in lst:
    for j in i:
        dict[j] += 1
for i in dict.values():
    print(i)

Submission status: Accepted

Solution code:
wlist = []
city, road = map(int, input().split())
for i in range(road):
    wlist.append(list(map(int, input().split())))
dst = []
for i in range(city):
    count = 0
    for k in wlist:
        if i+1 in k:
            count += 1
    dst.append(count)
for d in dst:
    print(d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M = map(int, input().split())
    result = [0] * N
    for _ in range(M):
        A, B = map(int, input().split())
        result[A - 1] += 1
        result[B - 1] += 1
    for m in result:
        print(m)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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 = map(int, input().split())
list = []
for x in range(n):
    list.append(0)
for y in range(m):
    a, b = map(int, input().split())
    list[a - 1] += 1
    list[b - 1] += 1
for id in range(n):
    print(list[id])

Submission status: Accepted

Solution code:
def cityroadcount(n , m , a):
    reans = []
    for i in range(1 , n + 1):
        count = 0
        for w in range(m):
            count += int(a[w].count(i))
        reans.append(count)

    return reans

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

    ans = cityroadcount(n , m , a)
    for i in range(n):
        print(ans[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(1, n+1):
    print(sum(c.count(str(i)) for c in connections))

Submission status: Accepted

Solution code:
# 問題を意訳するとai、biの出現回数をカウントするのが目的
import numpy as np
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for __ in range(M)]

ab = np.array(ab).flatten()
for i in range(1,N+1):
    print(len(np.where(ab == i)[0]))

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 = map(int, input().split())
ABs = [input().split() for i in range(M)]


MPs = {}
# この書き方でa,bが取り出せる
for a, b in ABs:
    a = int(a)  # intに直すには先に直しておく
    b = int(b)
    if a not in MPs:
        MPs[a] = 1
    else:
        MPs[a] += 1
    if b not in MPs:
        MPs[b] = 1
    else:
        MPs[b] += 1

for mp in range(1, N+1):
    if mp not in MPs:
        print(0)
    else:
        print(MPs[mp])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ABs = [input().split() for i in range(M)]
 
 
MPs = {}
for a, b in ABs:
    a = int(a)
    b = int(b)
    if a not in MPs:
        MPs[a] = 1
    else:
        MPs[a] += 1
    if b not in MPs:
        MPs[b] = 1
    else:
        MPs[b] += 1
 
for mp in range(1, N+1):
    if mp not in MPs:
        MPs[mp] = '0'
 
for _, y in sorted(MPs.items()):
    print(y)

Submission status: Accepted

Solution code:
N, M = tuple(map(int, input().split()))
cnt = [0 for _ in range(N+1)]
for _ in range(M):
    fr, to = tuple(map(int, input().split()))
    cnt[fr] += 1
    cnt[to] += 1
for i in range(1, N+1):
    print(cnt[i])

Submission status: Accepted

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

for i in range(m):
  ori, dst = map(int, input().split())
  load[ori-1][dst-1] += 1
  load[dst-1][ori-1] += 1

for j in range(n):
  print(sum(load[j]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
al = [0]*m; bl = [0]*m
for i in range(m):
    a,b = list(map(int, input().split()))
    al[i] = a
    bl[i] = b
res = [0] * n
for i in range(m):
    res[al[i]-1] += 1
    res[bl[i]-1] += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n, m = map(int, input().split())
roads = [tuple(map(int, input().split())) for _ in range(m)]

roadss = ()
for road in roads:
  roadss += road

cr = Counter(roadss)
for i in range(1, n+1):
  print(cr[i])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a, b = [0]*M, [0]*M
for i in range(M):
    tmp_a, tmp_b = map(int, input().split())
    a[i], b[i] = tmp_a, tmp_b
ab = zip(a,b)

# 添え字:都市,値:本数
num = [0]*(N+1)

for a_i, b_i in ab:
    num[a_i] += 1
    num[b_i] += 1

for i in range(len(num)):
    if i==0:
        continue
    else:
        print(num[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):
	x, y = map(int, input().split())
	if x in dic:
		dic[x] += 1
	else:
		dic[x] = 1
	if y in dic:
		dic[y] += 1
	else:
		dic[y] = 1
for i,j in sorted(dic.items()):
	print (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)
for i in range(1,n+1):
  print(li.count(i))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n,m = map(int,input().split())
cnt = [0]*n
for i in range(m):
	a,b = map(int,input().split())
	cnt[a-1] += 1
	cnt[b-1] += 1
for j in range(n):
	print(cnt[j])

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 l:
  print(i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
import sys

#n, a, b= map(int, input().split())
n, m  = map(int, input().split())
#s = list(str(input()))
#n = int(input())
#a = list(map(int, input().split()))

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

num = [int(i+1) for i in range(n)]
count = [0]*n

for i in range(m):
  for ii in range(n):
    if(a[i] == num[ii]):
      count[ii] = count[ii] + 1
    if(b[i] == num[ii]):
      count[ii] = count[ii] + 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
L = [0] * N

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

for i in L:
    print(i)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n, m = MAP()
L = [LIST() for i in range(m)]

R = [[0] * n for i in range(n)]

for a, b in L:
    R[a-1][b-1] += 1
    R[b-1][a-1] += 1

for r in R:
    print(sum(r))

Submission status: Accepted

Solution code:
tmp = input().split()
n = int(tmp[0])
m = int(tmp[1])

a = [0] * m
b = [0] * m

for i in range(m):
    tmp = input().split()
    tmp = list(map(int,tmp))
    a[i] = tmp[0]
    b[i] = tmp[1]

arr = [[0] * (n+1) for i in range(n+1)]

for i in range(m):
    arr[a[i]][b[i]] += 1
    arr[b[i]][a[i]] += 1

for i in range(1,n+1):
    count = 0
    for k in range(len(arr[i])):
        if arr[i][k] != 0:
            count += arr[i][k]
    print(count)

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())
# print(A,B)
for i in range(n):
    ans = 0
    for k in range(m):
        if (A[k] == i+1) or (B[k] == i+1):
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

dic = defaultdict(list)

for a, b in ab:
  dic[a-1].append(b-1)
  dic[b-1].append(a-1)

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

Submission status: Accepted

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

Submission status: Accepted

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

res = [0] *  N

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

for r in res:
    print(r)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
cities = {i: 0 for i in range(N)}

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

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

Submission status: Accepted

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

for k in range(n):
    for i in range(m):
        for j in range(2):
            if(k+1 == a[i][j]):
                cnt[k] += 1
for l in range(len(cnt)):
    print(cnt[l])

Submission status: Accepted

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

Submission status: Accepted

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

town_road = [0 for _ in range(N+2)]

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

Submission status: Accepted

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

Submission status: Accepted

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

a = []
b = []

for _ in range(m):
    aa,bb = input().split()    
    a.append(aa)
    b.append(bb)

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

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,m=INTM()
    road=[]
    for i in range(m):
        a,b=INTM()
        road.append(a)
        road.append(b)
    for i in range(n):
        ct=road.count(i+1)
        print(ct)
if __name__ == '__main__':
    do()

Submission status: Accepted

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

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

ans = []
for n in range(1, N+1):
    count = 0
    for i in range(M):
        for j in range(2):
            if ab[i][j] == n:
                count += 1
    ans.append(count)


for a in ans:
    print(a)

Submission status: Accepted

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

m_a = []
m_b = []
for i in range(m):
  m_a_tmp, m_b_tmp = map(int, input().split())
  m_a.append(m_a_tmp)
  m_b.append(m_b_tmp)

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

for a,b in zip(m_a, m_b):
  n_n[a-1] += 1
  n_n[b-1] += 1

for n in n_n:
  print(n)

Submission status: Accepted

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

import collections
c = collections.Counter(l)

for k, v in c.items():
    ans[k-1]+=v

for i in ans:
    print(i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#from fractions import gcd
#mod = 10 ** 9 + 7
#N = int(input())
#a = list(map(int,input().split()))
#a,b,c = map(int,input().split())

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:
import sys
input = sys.stdin.readline
N,M = [int(i) for i in input().split()]
nes = [0] * (N+1)
for i in range(M) :
    a,b = [int(j) for j in input().split()]
    nes[a] +=1
    nes[b] +=1
for i in range(1,N+1) :
    print(nes[i])

Submission status: Accepted

Solution code:
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
#print(ans)
#print(ans[1:])
#unpack
print(*ans[1:], sep='\n')

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())
ab = [list(map(int, input().split())) for _ in range(M)]

road = []
for _ in range(N):
  road.append(0)

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

for j in road:
  print(j)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = []
b = []
for i in range(M):
    a1 , b1 = [int(i) for i in input().split()]
    a.append(a1)
    b.append(b1)

nm = a+b

ans = [0 for i in range(N)]
for j in range(0,(len(nm))):
    i = nm[j]
    ans[i-1] += 1

for i in range(0,len(ans)):
    print(ans[i])

Submission status: Accepted

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

Submission status: Accepted

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

city = dict()

for i in range(n):
  city[i + 1] = 0
  
for i in range(m):
  s, e = list(map(int, input().split()))
  city[s] += 1
  city[e] += 1

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

for i in ans:
  print(i)

Submission status: Accepted

Solution code:
# ALC005 B

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

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

for _ in range(1, N+1):
    print(road_list.count(_))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

for ans in town:
    print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

# 各都市間の道路の本数は、ABに含まれる各都市の個数（番号）に等しい
roadsCntArray = []
# 入力に含まれる都市の個数を数える
for i in range(N):
    roadsCntArray.append(AB.count(i+1))
    print(roadsCntArray[i])

Submission status: Accepted

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

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

# 各都市間の道路の本数は、ABに含まれる各都市の個数（番号）に等しい
roadsCntArray = []
# 入力に含まれる都市の個数を数える
for i in range(N):
    roadsCntArray.append(AB.count(i+1))

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

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
city_road_nums = defaultdict(int)

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
#python3
import collections as col
n,m=map(int, input().split())
l=[]
for i in range(m):
  x,y=map(int, input().split())
  l.extend([x,y])

d=col.defaultdict(int, col.Counter(l))

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
g=[0 for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    g[a-1]+=1
    g[b-1]+=1
for i in g:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(M):
  li.append(list(map(int,input().split())))

for x in range(N):
  y = x + 1
  ans = 0
  for index, s in enumerate(li):
    if y == s[0]:
      ans += 1
    
    if y == s[1]:
      ans += 1
  
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
edge = []
node = [[]for i in range(N)]
for i in range(M):
    n = list(map(int,input().split()))
    n[0] -= 1
    n[1] -= 1
    node[n[0]].append(n[1])
    node[n[1]].append(n[0])
    edge.append(n)
for i in node:
    print(len(i))

Submission status: Accepted

Solution code:


import numpy as np
import fractions as fra



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


print(*a[1:],sep="\n")

Submission status: Accepted

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

for i in range(m):
  x=[int(j) for j in input().split()]
  road.extend(x)
for k in range(1,n+1):
  print(road.count(k))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().split()]
G = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = [int(x) for x in input().split()]
    G[a].append(b)
    G[b].append(a)
for i in range(1, (N + 1)):
    print(len(G[i]))

Submission status: Accepted

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

road = []
for i in range(m):
   tmp = [int(x) for x in input().split()]
   road.extend(tmp)

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

Submission status: Accepted

Solution code:
#061 b-counting roads
n,m=map(int,input().split())
ans=[0 for i in range(n)]
for i in range(m):
    x,y=map(int,input().split())
    ans[x-1]+=1
    ans[y-1]+=1
for x in ans:
    print(x)

Submission status: Accepted

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

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

ans =[ab.count(i) for i in range(1, n+1)]

for i in ans:
    print(i)