第 478 场 AtCoder Beginner Contest
E
小于与小于等于
lt and le
AtCoder
⌀ 1376
原题
← DF →

小于与小于等于AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

Determine whether there exists an integer sequence $A$ of length $N$ consisting of integers between $1$ and $N$, inclusive, that satisfies all of the following $Q$ conditions, and if it exists, find one.

请判断是否存在一个长度为 $N$ 的整数序列 $A$,其中的整数均在 $1$ 到 $N$(含)之间,并且满足以下全部 $Q$ 个条件;如果存在,请找出其中一个。AI (CI翻译)

The $i$-th condition $(1\le i\le Q)$ is given by a triple of integers $(t _ i,u _ i,v _ i)$, and is defined as follows.

第 $i$ 个条件 $(1\le i\le Q)$ 由三个整数 $(t _ i,u _ i,v _ i)$ 给出,具体定义如下。AI (CI翻译)

  • If $t _ i=0$: $A _ {u _ i}\le A _ {v _ i}$
  • If $t _ i=1$: $A _ {u _ i}\lt A _ {v _ i}$
  • 如果 $t _ i=0$:$A _ {u _ i}\le A _ {v _ i}$
  • 如果 $t _ i=1$:$A _ {u _ i}\lt A _ {v _ i}$
AI (CI翻译)

If there are multiple sequences satisfying all conditions, you may output any of them.

如果有多个序列满足所有条件,输出其中任意一个即可。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1\le N\le2\times10 ^ 5$
  • $1\le Q\le2\times10 ^ 5$
  • $t _ i\in\lbrace0,1\rbrace\ (1\le i\le Q)$
  • $1\le u _ i\le N\ (1\le i\le Q)$
  • $1\le v _ i\le N\ (1\le i\le Q)$
  • All input values are integers.
  • $1\le N\le2\times10 ^ 5$
  • $1\le Q\le2\times10 ^ 5$
  • $t _ i\in\lbrace0,1\rbrace\ (1\le i\le Q)$
  • $1\le u _ i\le N\ (1\le i\le Q)$
  • $1\le v _ i\le N\ (1\le i\le Q)$
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

N Q
t _ 1 u _ 1 v _ 1
t _ 2 u _ 2 v _ 2
\vdots
t _ Q u _ Q v _ Q

N Q
t _ 1 u _ 1 v _ 1
t _ 2 u _ 2 v _ 2
\vdots
t _ Q u _ Q v _ Q
AI (CI翻译)

Output

输出格式

AI (CI翻译)

On the first line, output Yes if an integer sequence satisfying the conditions exists, and No otherwise. If you output Yes on the first line, choose one integer sequence satisfying the conditions and output its elements, separated by spaces, on the second line. If there are multiple sequences satisfying all conditions, you may choose any of them.

第一行输出 Yes,表示存在满足条件的整数序列;如果不存在,则输出 No。如果第一行输出 Yes,请在第二行输出一个满足条件的整数序列,各元素之间用空格分隔。如果有多个序列满足所有条件,输出其中任意一个即可。AI (CI翻译)

样例

Input #1
7 8
0 1 4
0 2 6
0 3 2
1 3 5
0 4 1
0 4 3
1 5 7
0 6 7
Output #1
Yes
1 4 2 1 3 5 6
Let $A=(1,4,2,1,3,5,6)$; this is an integer sequence of length $7$ consisting of integers between $1$ and $7$, inclusive. Here, for example, the first condition $A _ 1\le A _ 4$ holds since $1\le 1$. The other seven conditions also hold, so the output corresponding to $A=(1,4,2,1,3,5,6)$ is considered correct. Additionally, $A=(1,1,1,1,2,2,3)$, $A=(3,5,4,3,6,7,7)$, and others also satisfy the conditions, so outputting these is also considered correct.
Input #2
1 1
1 1 1
Output #2
No
There is no integer sequence $A$ such that $A _ 1\lt A _ 1$ holds.
Input #3
15 20
0 9 8
1 6 1
0 6 8
0 11 1
0 4 2
1 11 12
0 4 14
1 10 1
0 12 12
1 7 12
1 13 1
1 5 9
1 10 14
1 14 1
1 8 12
0 10 12
1 4 15
1 3 9
0 5 14
0 10 2
Output #3
Yes
15 14 10 7 6 5 4 12 11 3 2 13 1 9 8
题目信息
题号
abc478_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。