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())
edge = [tuple(map(int, input().split())) for _ in range(m)]

connect = [0] * n
for a, b in edge:
    connect[a-1] += 1
    connect[b-1] += 1

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

Submission status: Accepted

Solution code:
# import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # queue
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    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])
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sqlite3
from contextlib import closing
N, M = [int(x) for x in input().split()]

with closing(sqlite3.connect(':memory:')) as con:
    c = con.cursor()
    c.execute('create table Edges (src int, dst int)')

    for _ in range(M):
        a, b = [int(x) for x in input().split()]
        c.execute('insert into Edges values (?, ?)', (a, b))

    for i in range(N):
        query = 'select count(*) from Edges where src = ? or dst = ?'
        for row in c.execute(query, (i + 1, i + 1)):
            print(row[0])

Submission status: Accepted

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

a = [0] * M
b = [0] * M

count = [0] * N

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

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
n, m = map(int, input().split())

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

for i in range(n):
    cnt = 0
    for rd in road:
        if rd.count(i+1) > 0:
            cnt+=1
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

s = [0 for i in range(n)]
for i in range(m * 2):
    s[sum(a, [])[i] - 1] += 1

for i in s:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    n,m = map(int,input().strip().split())
    l=[[] for _ in range(n)]
    for _ in range(m):
        a,b = map(int,input().strip().split())
        a,b = a-1, b-1
        l[a].append(b)
        l[b].append(a)
    for i in range(n):
        print(len(l[i]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
[n,m]=list(map(int,input().split()))
roads=[]
for i in range(m):
    road=list(map(int,input().split()))
    roads.append(road)
ans=[]
for i in range(n):
    kaisu=0
    for j in range(m):
        if roads[j][0]==i+1 or roads[j][1]==i+1:
            kaisu+=1
    ans.append(kaisu)

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

Submission status: Accepted

Solution code:
import sys

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

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

toshi_flag = [0] * n

for i in range(len(toshi)):
    for j in range(len(toshi[i])):
        toshi_flag[toshi[i][j] - 1] += 1

for item in toshi_flag:
    print("{}".format(item))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n):
    print(len(c[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(1, n+1):
    cnt = 0
    for j in l:
        cnt += j.count(i)
    print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter

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

l = []

for _ in range(M):
    a, b = input().split()
    l.append(str(a))
    l.append(str(b))

# c = Counter(l)
# c = sorted(dict(c).items(), key=lambda x:x[0])


nums = [str(i) for i in range(1, N + 1, 1)]

for num in nums:
    print(l.count(num))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[[] for _ in [0]*n]
for _ in [0]*m:
  a,b=map(int,input().split())
  l[a-1].append(b)
  l[b-1].append(a)
for i in l:
  print(len(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:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():

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

    for k in range(1,N+1):
        cnt=0
        for i in A:
            for j in i:
                if j==k:
                    cnt+=1
        print(cnt)

        

resolve()

Submission status: Accepted

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

dic = {}

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

    try:
        dic[a] += 1
    except:
        dic[a] = 1

    try:
        dic[b] += 1
    except:
        dic[b] = 1

#dic = sorted(dic.items(),key=lambda x:x[0])

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

Submission status: Accepted

Solution code:
n,m = [int(i) for i in input().split()]
ab = []
for i in range(m):
  ay = list(map(int,input().split()))
  ab.append(ay)
ans = []
for i in range(n):
  ans.append(0)
for i in range(m):
  for j in range(1,n+1):
    #print(i,j)
    if j in ab[i]:
      ans[j-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.append(a)
    c.append(b)
for j in range(N):
    print(c.count(j+1))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    c = Counter(a + b)
    for i in range(1, N + 1):
        print(c[i])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)


if __name__ == '__main__':
    main()

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:

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

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

for j in range(n):
    print(city[j][1])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

def main():
    mod=10**9+7
    N,M=MI()
    cnt=[0]*N
    for i in range(M):
        a,b=MI()
        a-=1
        b-=1
        cnt[a]+=1
        cnt[b]+=1
        
    for i in range(N):
        print(cnt[i])

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N, M = map(int,input().split())
C = [0] * (N+1)

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

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())
road = [0]*n
src = [tuple(map(int,input().split())) for i in range(m)]
for a , b in src:
    road[a-1] += 1
    road[b-1] += 1
for r in road:
    print(r)

Submission status: Accepted

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

Submission status: Accepted

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

ans=[0]*N
for a in A:
    ans[a[0]-1]+=1
    ans[a[1]-1]+=1

for a in ans:
    print(a)

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())
c = [0]*N
for _ in range(M):
  a,b = map(int,input().split())
  c[a-1] += 1
  c[b-1] += 1
for e in c:
  print(e)

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


N, M = MI()
d = {i: 0 for i in range(N)}
for _ in range(M):
    a, b = MI()
    d[a - 1] += 1
    d[b - 1] += 1
for i in range(N):
    print(d[i])

Submission status: Accepted

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

roads = {i : 0 for i in range(N)}
for path in paths:
  roads[path[0]-1] +=1
  roads[path[1]-1] +=1

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import string

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#061_B
n,m=map(int,input().split())
ans=[0 for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    ans[a-1]+=1
    ans[b-1]+=1
print(*ans,sep='\n')

Submission status: Accepted

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

for i in g:
    print(len(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(n):
    print(r.count(i+1))

Submission status: Accepted

Solution code:
#ABC061

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

for i in range(m):
    c[a[i][0]-1] += 1
    c[a[i][1]-1] += 1
for j in range(n):
    print(c[j])

Submission status: Accepted

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

ans = []
cnt = 0

for i in range(1, N+1):
    ans.append(cnt)
    cnt = 0
    for j in num_list:
        if i == j:
            cnt += 1

ans.append(cnt)
for i in range(1, N+1):
    print(ans[i])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for i in range(1,n+1):
    x = 0
    for j in range(len(l)):
        if i == l[j]:
            x += 1
    print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a = [None] * M
b = [None] * M
for i in range(M):
  a[i],b[i] = map(int,input().split())
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())
root_dic = {}
for i in range(N):
    root_dic[i+1] = 0
for i in range(M):
    root = list(map(int, input().split()))
    for i in range(2):
        root_dic[root[i]] += 1
for i, v in sorted(root_dic.items()):
    print(v)

Submission status: Accepted

Solution code:
n, m = [int(e) for e in input().split()]
map_dict = {}
for i in range(n):
    map_dict[str(i+1)] = 0
for _ in range(m):
    cities = [e for e in input().split()]
    map_dict[cities[0]]+=1
    map_dict[cities[1]]+=1
for i in range(n):
    print(map_dict[str(i+1)])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for j in ans:
  for i in l:
    if i[0]==j or i[1]==j:
      d[j]+=1
for i in d:
  print(d[i])

Submission status: Accepted

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

a_lis = []
b_lis = []

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

new_lis = a_lis + b_lis
set_new_lis = sorted(set(new_lis))
set_new_lis

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

Submission status: Accepted

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

import sys
import os
import math

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

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

    A[a] += 1
    A[b] += 1

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

Submission status: Accepted

Solution code:
def main():
    cities, roads = map(int, input().split())
    count = [0] * cities
    for _ in range(roads):
        begin, end = map(int, input().split())
        count[begin - 1] += 1
        count[end - 1] += 1
    for i in range(cities):
        print(count[i])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

bridges = []

for i in range(m):
    bridges += list(map(int, input().split(' ')))
    
counter  = [0] * n
for i in range(m * 2):
    counter[bridges[i] - 1] += 1

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

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:
import numpy as np
N,K=map(int,input().split())
A=np.zeros(N)
for i in range(K):
  S=list(map(int,input().split()))
  A[S[0]-1]+=1
  A[S[1]-1]+=1
for i in range(N):
  print(int(A[i]))

Submission status: Accepted

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

lst2 = [0]*n

for i,j in lst1:
    lst2[i-1] += 1
    lst2[j-1] += 1

for i in lst2:
    print(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 x in ans:
  print(x)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M  = map(int, input().split())
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:
a,b=map(int,input().split())
t=[0]*b
x=[0]*b
N=1
for i in range(b):
    t[i],x[i] = map(int,input().split())
A=t+x
for z in range(a):
    print(A.count(N))
    N+=1

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = []
b = []
count_raw = []
count = 0

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

a.extend(b)

for i in range(1, N+1):
    count = 0
    for j in range(0, 2*M):
        if a[j] == i:
            count += 1
    count_raw.append(count)

for i in range(0, N):
    print(count_raw[i])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
li = [list(map(int, input().split())) for i in range(M)]
dic = {}
for i in range(N) :
    dic[i] = 0
for l in li :
    dic[l[0] - 1] += 1
    dic[l[1] - 1] += 1
for v in dic.values() :
    print(v)

Submission status: Accepted

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

Submission status: Accepted

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


#----------
N,M = list(map(int, input().rstrip().split()))
roads = [list(map(int, input().rstrip().split())) for _ in range(M)]
#----------
city_road = { str(i):0 for i in range(1,N+1)}

for a,b in roads:
    city_road[str(a)] += 1
    city_road[str(b)] += 1

for i in range(1,N+1):
    print(city_road[str(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 = [int(i) for i in input().split()]
G = [0]*N
for i in range(M):
    a, b = [int(i)-1 for i in input().split()]
    G[a]+=1
    G[b]+=1

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    roads = [list(input().split()) for _ in range(M)]
    road_num = defaultdict(int)
    for road in roads:
        road_num[road[0]] += 1
        road_num[road[1]] += 1
    for i in range(1, N+1):
        print(road_num[str(i)])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:


if __name__ == '__main__':
    N,M=list(map(int,input().split()))
    roads=[0 for i in range(N)]
    for i in range(M):
        a,b=list(map(int,input().split()))
        roads[a-1]+=1
        roads[b-1]+=1

    for road in roads:
        print(road)

Submission status: Accepted

Solution code:
[N, M] = list(map(int, input().split()))
[s, e] = [ [], [] ]
for _ in range(M):
  input_line = list(map(int, input().split()))
  s.append(input_line[0])
  e.append(input_line[1])
bucket = {}
for i in range(1, N+1):
  bucket[i] = []

for i in range(M):
  if s[i] in bucket and e[i] in bucket:
    bucket[s[i]].append(s[i])
    bucket[e[i]].append(e[i])
  elif s[i] in bucket:
    bucket[s[i]].append(s[i])
    bucket[e[i]] = [e[i]]
  elif e[i] in bucket:
    bucket[s[i]] = [s[i]]
    bucket[e[i]].append(e[i])
  else:
    bucket[s[i]] = [s[i]]
    bucket[e[i]] = [e[i]]

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(0,M):
	lst.extend(input().split(" "))
for i in range(1,N+1):
	print(lst.count("{}".format(i)))

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
abList = [list(map(int, input().split())) for _ in range(m)]
num = [0 for _ in range(n + 1)]
for i in range(m):
    for j in range(2):
        num[abList[i][j]] += 1
for i in range(n):
    print(num[i + 1])

Submission status: Accepted

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

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

d={}
for i in range(m):
    a,b=map(int,input().split())
    if a in d:
        d[a]=d[a]+1
    else:
        d[a]=1

    if b in d:
        d[b]=d[b]+1
    else:
        d[b]=1

for i in range(n):
    if i+1 in d:
        print(d[i+1])
    else:
        print(0)