Codeforces Round 816 (Div. 2)
D
2+ doors
Codeforces
1900
原题
← CE →
翻译中…

The Narrator has an integer array $a$ of length $n$, but he will only tell you the size $n$ and $q$ statements, each of them being three integers $i, j, x$, which means that $a_i \mid a_j = x$, where $|$ denotes the bitwise OR operation.

翻译中…

Find the lexicographically smallest array $a$ that satisfies all the statements.

翻译中…

An array $a$ is lexicographically smaller than an array $b$ of the same length if and only if the following holds:

翻译中…
  • in the first position where $a$ and $b$ differ, the array $a$ has a smaller element than the corresponding element in $b$.
翻译中…

Input

翻译中…

In the first line you are given with two integers $n$ and $q$ ($1 \le n \le 10^5$, $0 \le q \le 2 \cdot 10^5$).

翻译中…

In the next $q$ lines you are given with three integers $i$, $j$, and $x$ ($1 \le i, j \le n$, $0 \le x \lt 2^{30}$) — the statements.

翻译中…

It is guaranteed that all $q$ statements hold for at least one array.

翻译中…

Output

翻译中…

On a single line print $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \lt 2^{30}$) — array $a$.

翻译中…

Note

翻译中…

In the first sample, these are all the arrays satisfying the statements:

翻译中…
  • $[0, 3, 2, 2]$,
  • $[2, 1, 0, 0]$,
  • $[2, 1, 0, 2]$,
  • $[2, 1, 2, 0]$,
  • $[2, 1, 2, 2]$,
  • $[2, 3, 0, 0]$,
  • $[2, 3, 0, 2]$,
  • $[2, 3, 2, 0]$,
  • $[2, 3, 2, 2]$.
翻译中…

样例

Input #1
4 3
1 2 3
1 3 2
4 1 2
Output #1
0 3 2 2
InputCopy OutputCopy
Input #2
1 0
Output #2
0
InputCopy OutputCopy
Input #3
2 1
1 1 1073741823
Output #3
1073741823 0
InputCopy OutputCopy
题目信息
题号
1715D
时间限制
1.5 s
内存限制
256 MB
标签
2-SAT
位运算
图论
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。