1285 : 不等式
时间限制Time Limit
1
秒Sec
内存限制Memory Limit
512
兆MB
提交次数Submitted
702 次Times
通过次数Solved
181 次Times
标准评测 Standard
从标准输入读入,结果写到标准输出。评测将输出拆成 token,与标准答案逐项比较,不按整段逐字节比对。
Read from standard input and write to standard output. The judge splits the output into tokens and compares them with the official answer; it does not compare raw bytes.
| 比对Compare | token 相同即通过。中间的空格、制表符、换行可多可少。Matching tokens pass. Extra spaces, tabs, or newlines between them are ignored. |
|---|---|
| 不同则错Differs | token 个数或内容不同即错误。23 与 2 3、02 与 2、2.0 与 2 均视为不同。A different token count or value is wrong. 23 vs 2 3, 02 vs 2, and 2.0 vs 2 all differ. |
| 输入Input | 标准输入,格式见题面。Standard input; format as in the statement. |
| 输出Output | 标准输出。Standard output. |
题目描述Description
给定 \(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\)。
输入格式Input
第一行两个整数 \(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)\)。
输出格式Output
输出一行一个整数,表示答案。
样例Sample
提示Hint
和最小的解为 \((3,1,2,1,1)\),和为 \(8\)。
出题Author
THU