CF1430G.Yet Another DAG Problem
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a directed acyclic graph (a directed graph that does not contain cycles) of n vertices and m arcs. The i-th arc leads from the vertex xi to the vertex yi and has the weight wi.
Your task is to select an integer av for each vertex v, and then write a number bi on each arcs i such that bi=axi−ayi. You must select the numbers so that:
- all bi are positive;
- the value of the expression i=1∑mwibi is the lowest possible.
It can be shown that for any directed acyclic graph with non-negative wi, such a way to choose numbers exists.
给你一个包含 n 个顶点和 m 条有向边的有向无环图(即不含环的有向图)。第 i 条边从顶点 xi 指向顶点 yi,其权值为 wi。
你的任务是为每个顶点 v 选定一个整数 av,并在每条边 i 上写一个数 bi,使得 bi=axi−ayi。你需要选择这些数,满足以下条件:
- 所有 bi 均为正数;
- 表达式 i=1∑mwibi 的值尽可能小。
可以证明:对于任意边权 wi 非负的有向无环图,总存在满足上述要求的选取方式。
输入格式
The first line contains two integers n and m (2≤n≤18; 0≤m≤2n(n−1)).
Then m lines follow, the i-th of them contains three integers xi, yi and wi (1≤xi,yi≤n, 1≤wi≤105, xi=yi) — the description of the i-th arc.
It is guaranteed that the lines describe m arcs of a directed acyclic graph without multiple arcs between the same pair of vertices.
第一行包含两个整数 n 和 m(2≤n≤18;0≤m≤2n(n−1))。
接下来是 m 行,其中第 i 行包含三个整数 xi、yi 和 wi(1≤xi,yi≤n,1≤wi≤105,xi=yi),表示第 i 条有向边的描述。
保证这些行描述了一个有向无环图(DAG)的 m 条边,且任意一对顶点之间不存在重边。
输出格式
Print n integers a1, a2, ..., an (0≤av≤109), which must be written on the vertices so that all bi are positive, and the value of the expression i=1∑mwibi is the lowest possible. If there are several answers, print any of them. It can be shown that the answer always exists, and at least one of the optimal answers satisfies the constraints 0≤av≤109.
输出 n 个整数 a1, a2, ..., an(满足 0≤av≤109),这些整数需写在图的顶点上,使得所有 bi 均为正数,且表达式 i=1∑mwibi 的值尽可能小。若存在多个满足条件的答案,输出任意一个即可。可以证明:答案一定存在,且至少存在一个最优解满足约束 0≤av≤109。
输入输出样例
输入#1
3 2 2 1 4 1 3 2
输出#1
1 2 0
输入#2
5 4 1 2 1 2 3 1 1 3 6 4 5 8
输出#2
43 42 41 1337 1336
输入#3
5 5 1 2 1 2 3 1 3 4 1 1 5 1 5 4 10
输出#3
4 3 2 1 2
输入解题思路,AI测评打分。不知道怎么写?