CF1715D.2+ doors

普及+/提高

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The Narrator has an integer array aa of length nn, but he will only tell you the size nn and qq statements, each of them being three integers i,j,xi, j, x, which means that ai∣aj=xa_i \mid a_j = x, where ∣| denotes the bitwise OR operation.

Find the lexicographically smallest array aa that satisfies all the statements.

An array aa is lexicographically smaller than an array bb of the same length if and only if the following holds:

  • in the first position where aa and bb differ, the array aa has a smaller element than the corresponding element in bb.

叙述者有一个长度为 nn 的整数数组 aa,但他只会告诉你数组长度 nn 以及 qq 条陈述,每条陈述由三个整数 i,j,xi, j, x 构成,表示 ai∣aj=xa_i \mid a_j = x,其中 ∣| 表示按位或运算。

请找出满足所有陈述的字典序最小的数组 aa。

当且仅当满足以下条件时,数组 aa 的字典序小于同长度的数组 bb:

  • 在 aa 与 bb 首次出现差异的位置上,aa 中对应位置的元素小于 bb 中对应位置的元素。

输入格式

In the first line you are given with two integers nn and qq (1≤n≤1051 \le n \le 10^5, 0≤q≤2⋅1050 \le q \le 2 \cdot 10^5).

In the next qq lines you are given with three integers ii, jj, and xx (1≤i,j≤n1 \le i, j \le n, 0≤x<2300 \le x \lt 2^{30}) — the statements.

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

第一行给出两个整数 nn 和 qq(1≤n≤1051 \le n \le 10^5,0≤q≤2⋅1050 \le q \le 2 \cdot 10^5)。

接下来 qq 行,每行给出三个整数 ii、jj 和 xx(1≤i,j≤n1 \le i, j \le n,0≤x<2300 \le x \lt 2^{30})——这些是约束条件。

保证存在至少一个数组满足全部 qq 个约束条件。

输出格式

On a single line print nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai<2300 \le a_i \lt 2^{30}) — array aa.

在一行中输出 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai<2300 \le a_i \lt 2^{30})—— 数组 aa。

输入输出样例

  • 输入#1

    4 3
    1 2 3
    1 3 2
    4 1 2

    输出#1

    0 3 2 2
  • 输入#2

    1 0

    输出#2

    0
  • 输入#3

    2 1
    1 1 1073741823

    输出#3

    1073741823 0

说明/提示

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

  • [0,3,2,2][0, 3, 2, 2],
  • [2,1,0,0][2, 1, 0, 0],
  • [2,1,0,2][2, 1, 0, 2],
  • [2,1,2,0][2, 1, 2, 0],
  • [2,1,2,2][2, 1, 2, 2],
  • [2,3,0,0][2, 3, 0, 0],
  • [2,3,0,2][2, 3, 0, 2],
  • [2,3,2,0][2, 3, 2, 0],
  • [2,3,2,2][2, 3, 2, 2].

在第一个样例中,所有满足条件的数组如下:

  • [0,3,2,2][0, 3, 2, 2],
  • [2,1,0,0][2, 1, 0, 0],
  • [2,1,0,2][2, 1, 0, 2],
  • [2,1,2,0][2, 1, 2, 0],
  • [2,1,2,2][2, 1, 2, 2],
  • [2,3,0,0][2, 3, 0, 0],
  • [2,3,0,2][2, 3, 0, 2],
  • [2,3,2,0][2, 3, 2, 0],
  • [2,3,2,2][2, 3, 2, 2]。

输入解题思路,AI测评打分。不知道怎么写?

首页