CF1387A.Graph

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an undirected graph where each edge has one of two colors: black or red.

Your task is to assign a real number to each node so that:

  • for each black edge the sum of values at its endpoints is 11;
  • for each red edge the sum of values at its endpoints is 22;
  • the sum of the absolute values of all assigned numbers is the smallest possible.

Otherwise, if it is not possible, report that there is no feasible assignment of the numbers.

给你一个无向图,其中每条边具有两种颜色之一:黑色或红色。

你的任务是为每个节点分配一个实数,使得:

  • 对于每条黑边,其两个端点处的数值之和为 11;
  • 对于每条红边,其两个端点处的数值之和为 22;
  • 所有分配数值的绝对值之和尽可能小。

否则,若不存在满足条件的赋值方案,则报告不存在可行的数值分配。

输入格式

The first line contains two integers NN (1≤N≤100 0001 \leq N \leq 100\,000) and MM (0≤M≤200 0000 \leq M \leq 200\,000): the number of nodes and the number of edges, respectively. The nodes are numbered by consecutive integers: 1,2,…,N1, 2, \ldots, N.

The next MM lines describe the edges. Each line contains three integers aa, bb and cc denoting that there is an edge between nodes aa and bb (1≤a,b≤N1 \leq a, b \leq N) with color cc (11 denotes black, 22 denotes red).

第一行包含两个整数 NN(1≤N≤100 0001 \leq N \leq 100\,000)和 MM(0≤M≤200 0000 \leq M \leq 200\,000):分别为节点数和边数。节点编号为连续整数:1,2,…,N1, 2, \ldots, N。

接下来的 MM 行描述各条边。每行包含三个整数 aa、bb 和 cc,表示节点 aa 与节点 bb(1≤a,b≤N1 \leq a, b \leq N)之间存在一条颜色为 cc 的边(11 表示黑色,22 表示红色)。

输出格式

If there is a solution, the first line should contain the word "YES" and the second line should contain NN space-separated numbers. For each ii (1≤i≤N1 \le i \le N), the ii-th number should be the number assigned to the node ii.

Output should be such that:

  • the sum of the numbers at the endpoints of each edge differs from the precise value by less than 10−610^{-6};
  • the sum of the absolute values of all assigned numbers differs from the smallest possible by less than 10−610^{-6}.

If there are several valid solutions, output any of them.

If there is no solution, the only line should contain the word "NO".

如果存在解,则第一行应包含单词“YES”,第二行应包含 NN 个用空格分隔的数字。对于每个 ii(1≤i≤N1 \le i \le N),第 ii 个数字应为分配给节点 ii 的数值。

输出需满足以下条件:

  • 每条边两个端点处数值之和与精确值的差的绝对值小于 10−610^{-6};
  • 所有分配数值的绝对值之和与可能的最小值的差的绝对值小于 10−610^{-6}。

若存在多个合法解,输出任意一个即可。

若无解,则仅输出一行单词“NO”。

输入输出样例

  • 输入#1

    4 4
    1 2 1
    2 3 2
    1 3 2
    3 4 1

    输出#1

    YES
    0.5 0.5 1.5 -0.5
  • 输入#2

    2 1
    1 2 1

    输出#2

    YES
    0.3 0.7
  • 输入#3

    3 2
    1 2 2
    2 3 2

    输出#3

    YES
    0 2 0
  • 输入#4

    3 4
    1 2 2
    2 2 1
    2 1 1
    1 2 2

    输出#4

    NO

说明/提示

Note that in the second example the solution is not unique.

注意,在第二个例子中,解不是唯一的。

输入解题思路,AI测评打分。不知道怎么写?

首页