CF1430G.Yet Another DAG Problem

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a directed acyclic graph (a directed graph that does not contain cycles) of nn vertices and mm arcs. The ii -th arc leads from the vertex xix_i to the vertex yiy_i and has the weight wiw_i .

Your task is to select an integer ava_v for each vertex vv , and then write a number bib_i on each arcs ii such that bi=axiayib_i = a_{x_i} - a_{y_i} . You must select the numbers so that:

  • all bib_i are positive;
  • the value of the expression i=1mwibi\sum \limits_{i = 1}^{m} w_i b_i is the lowest possible.

It can be shown that for any directed acyclic graph with non-negative wiw_i , such a way to choose numbers exists.

输入格式

The first line contains two integers nn and mm ( 2n182 \le n \le 18 ; 0mn(n1)20 \le m \le \dfrac{n(n - 1)}{2} ).

Then mm lines follow, the ii -th of them contains three integers xix_i , yiy_i and wiw_i ( 1xi,yin1 \le x_i, y_i \le n , 1wi1051 \le w_i \le 10^5 , xiyix_i \ne y_i ) — the description of the ii -th arc.

It is guaranteed that the lines describe mm arcs of a directed acyclic graph without multiple arcs between the same pair of vertices.

输出格式

Print nn integers a1a_1 , a2a_2 , ..., ana_n ( 0av1090 \le a_v \le 10^9 ), which must be written on the vertices so that all bib_i are positive, and the value of the expression i=1mwibi\sum \limits_{i = 1}^{m} w_i b_i 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 0av1090 \le a_v \le 10^9 .

输入输出样例

  • 输入#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
首页