B - Counting Roads Editorial /

Time Limit: 2 sec / Memory Limit: 256 MiB

配点 : 200200

問題文

NN 個の都市があり、MM 本の道路があります。
i(1iM)i(1≦i≦M) 番目の道路は、都市 aia_i と 都市 bib_i (1ai,biN)(1≦a_i,b_i≦N) を双方向に結んでいます。
同じ 22 つの都市を結ぶ道路は、11 本とは限りません。
各都市から他の都市に向けて、何本の道路が伸びているか求めてください。

制約

  • 2N,M502≦N,M≦50
  • 1ai,biN1≦a_i,b_i≦N
  • aibia_i ≠ b_i
  • 入力は全て整数である。

入力

入力は以下の形式で標準入力から与えられる。

NN MM
a1a_1 b1b_1
::  
aMa_M bMb_M

出力

答えを NN 行に出力せよ。
i(1iN)i(1≦i≦N) 行目には、都市 ii から他の都市に向けて、何本の道路が伸びているかを出力せよ。


入力例 1Copy

Copy
4 3
1 2
2 3
1 4

出力例 1Copy

Copy
2
2
1
1
  • 都市 11 からは 11 番目と 33 番目の道路が伸びています。
  • 都市 22 からは 11 番目と 22 番目の道路が伸びています。
  • 都市 33 からは 22 番目の道路が伸びています。
  • 都市 44 からは 33 番目の道路が伸びています。

入力例 2Copy

Copy
2 5
1 2
2 1
1 2
2 1
1 2

出力例 2Copy

Copy
5
5

入力例 3Copy

Copy
8 8
1 2
3 4
1 5
2 8
3 7
5 2
4 1
6 8

出力例 3Copy

Copy
3
3
2
2
2
1
1
2

Score : 200200 points

Problem Statement

There are NN cities and MM roads. The ii-th road (1iM)(1≤i≤M) connects two cities aia_i and bib_i (1ai,biN)(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

  • 2N,M502≤N,M≤50
  • 1ai,biN1≤a_i,b_i≤N
  • aibia_i ≠ b_i
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

NN MM
a1a_1 b1b_1
::  
aMa_M bMb_M

Output

Print the answer in NN lines. In the ii-th line (1iN)(1≤i≤N), print the number of roads connected to city ii.


Sample Input 1Copy

Copy
4 3
1 2
2 3
1 4

Sample Output 1Copy

Copy
2
2
1
1
  • City 11 is connected to the 11-st and 33-rd roads.
  • City 22 is connected to the 11-st and 22-nd roads.
  • City 33 is connected to the 22-nd road.
  • City 44 is connected to the 33-rd road.

Sample Input 2Copy

Copy
2 5
1 2
2 1
1 2
2 1
1 2

Sample Output 2Copy

Copy
5
5

Sample Input 3Copy

Copy
8 8
1 2
3 4
1 5
2 8
3 7
5 2
4 1
6 8

Sample Output 3Copy

Copy
3
3
2
2
2
1
1
2


2025-06-21 (Sat)
18:38:16 +00:00