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

#BF0000042. Các chuyến bay (Flights)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Các chuyến bay (Flights)

Flights

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

The flight network is a directed acyclic graph. Give each flight duration 11 or 22 such that every route from city 11 to city nn has the same travel time, or print No.

Input

First line n,mn,m; then mm lines ai,bia_i,b_i.

Output

Print No, or print Yes followed by mm durations (11 or 22) in input order.

Subtasks

  • Subtask 1 (20 points): 2≤n≤122\le n\le12, 1≤m≤301\le m\le30; 1≤ai<bi≤n1\le a_i<b_i\le n; no duplicate arcs; a path from 11 to nn exists.
  • Subtask 2 (30 points): 2≤n≤1502\le n\le150, 1≤m≤5001\le m\le500; 1≤ai<bi≤n1\le a_i<b_i\le n; no duplicate arcs; a path from 11 to nn exists.
  • Subtask 3 (50 points): 2≤n≤10002\le n\le1000, 1≤m≤50001\le m\le5000; 1≤ai<bi≤n1\le a_i<b_i\le n; no duplicate arcs; a path from 11 to nn exists.

Examples

Input

3 3
1 2
2 3
1 3

Output

Yes
1
1
2

Explanation

The two-flight route 1→2→31\to2\to3 takes 1+1=21+1=2 hours. Setting the direct flight duration to 22 gives the same total time. Thus 1,1,21,1,2 is a valid set of flight durations.