問題一覧 > 通常問題

No.3568 Range Restriction

レベル : / AI推定難易度 : 2300 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 9
作問者 : 👑 to-omer / テスター : 👑 hamamu
お気に入りにしたユーザー ProblemId : 13219 / 自分の提出
問題文最終更新日: 2026-03-20 20:13:15
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 501 (順位表) の他の問題:

Problem Statement

Determine whether there exists a sequence of non-negative integers $A=(A_1,A_2,\dots,A_N)$ of length $N$ that satisfies all of the following conditions for $i=1,\dots,M$, and if one exists, find the one with the minimum sum.

  • $A_{x_i}+A_{y_i}\ge v_i \Rightarrow l_i \le A_{z_i} \le r_i$

You are given $T$ test cases; find the answer for each of them.

Constraints

  • $1\le T\le 2\times 10^{5}$
  • $1\le N,M\le 2\times 10^5$
  • $1\le x_i,y_i,z_i\le N$
  • $0\le v_i,l_i,r_i\le 10^9$
  • The sum of $N$ over a single input is at most $2\times 10^5$.
  • The sum of $M$ over a single input is at most $2\times 10^5$.

Input

$T$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_T$

Each test case is given in the following format.

$N$ $M$
$x_1$ $y_1$ $z_1$ $v_1$ $l_1$ $r_1$
$x_2$ $y_2$ $z_2$ $v_2$ $l_2$ $r_2$
$\vdots$
$x_M$ $y_M$ $z_M$ $v_M$ $l_M$ $r_M$

Output

For each test case, if no integer sequence satisfying the conditions exists, print -1; if one exists, print the elements of the integer sequence $A$ with the minimum sum, separated by spaces.

Sample

Sample 1
Input
3
3 3
1 2 3 0 1 5
1 3 2 4 2 7
2 3 1 1 3 4
1 2
1 1 1 0 1 1
1 1 1 0 2 2
4 1
1 2 3 3 2 1
Output
3 2 1
-1
0 0 0 0

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。