PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000121. Đếm đỉnh có thể đến (Reachable Nodes)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm đỉnh có thể đến (Reachable Nodes)

Reachable Nodes

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given a directed acyclic graph with nn vertices, count for every vertex uu how many distinct vertices are reachable from uu, including uu itself via a zero-edge walk. A destination is counted once even when multiple paths lead to it.

Input

First line n,mn,m, followed by mm directed edges u,vu,v, u≠vu\ne v. Vertices are 11-indexed.

Output

Print nn integers in vertex order.

Subtasks

  • Subtask 1 (40 points): 1≤n≤151\le n\le 15, 0≤m≤300\le m\le 30. All input conditions remain in force.

  • Subtask 2 (60 points): 1≤n≤5⋅1041\le n\le 5\cdot 10^4, 0≤m≤1050\le m\le 10^5. All input conditions remain in force.

Examples

Input

5 6
1 2
1 3
1 4
2 3
3 5
4 5

Output

5 3 2 2 1

Explanation

Node 1 reaches all five nodes. Nodes 2,3,4,5 respectively reach 3,2,2,1 nodes.