#P10309. Tree Edge Weight Assignment

    ID: 12311 Type: Default 1000ms 256MiB

Tree Edge Weight Assignment

Tree Edge Weight Assignment

You are given a tree GG with nn nodes and an integer EE. Your task is to assign an integer weight wiw_i to each edge of the tree such that:

  1. 1wi1091 \le w_i \le 10^9 for every edge.
  2. Define dis(u,v)dis(u,v) as the sum of the weights along the unique simple path between nodes uu and vv. For a node uu, let [ M(u)= \max_{v=1}^{n} dis(u,v), ] and consider a node uu chosen uniformly at random from 11 to nn. The expected value of M(u)M(u), taken modulo 998244353998244353, must be exactly EE.

If there is no valid assignment of weights that satisfies these conditions, output -1.

If you are not familiar with computing expectations and working with modular arithmetic in this setting, please refer to the template problem P2613 \textbf{Template: Rational Numbers Modulo} for guidance.

inputFormat

The first line contains two integers nn and EE (1n1051 \le n \le 10^5 and 0E9982443520 \le E \le 998244352). The following n1n-1 lines each contain two integers uu and vv describing an edge between nodes uu and vv in the tree.

outputFormat

If there exists an assignment of weights satisfying the conditions, output n1n-1 space‐separated integers representing the weight for each edge in the order of input. Otherwise, output -1.

Note: In a tree with one node (n=1n=1), since there are no edges, output an empty line if E=0E=0, otherwise output -1.

sample

1 0