QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#8760. 不等式

統計

题目描述

给定 $n,m$,以及 $m$ 个形如 $a_{x_i}\ge a_{y_i}+a_{z_i}(1 \le i \le m)$ 的条件。问是否有一组正整数 $(a_1,a_2,\cdots,a_n)$ 满足所有条件,并且 $a_1+a_2+\cdots+a_n \le 10^{9}$。如果有,输出 $a_1+a_2+\cdots+a_n$ 的最小值;如果无解,输出 $-1$。

输入格式

从标准输入读入数据。

第一行两个整数 $n,m(1 \le n,m \le 2\times 10^5)$。

之后 $m$ 行,第 $i$ 行三个整数 $x_i,y_i,z_i$,表示一个限制 $a_{x_i}\ge a_{y_i}+a_{z_i}(1\le x_i,y_i,z_i \le n)$。

输出格式

输出到标准输出。

输出一行一个整数,表示答案。

样例

输入

5 2
1 2 3
3 4 5

输出

8

解释

和最小的解为 $(3,1,2,1,1)$,和为 $8$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.