×

计蒜客

  1. 题库
  2. Fish eating fruit
  3. 问答
  • 32.39%
  • 262144K

State Z is a underwater kingdom of the Atlantic Ocean. This country is amazing. There are $n$ cities in the country and $n-1$ undirected underwater roads which connect all cities.

In order to save energy and avoid traffic congestion, the king promulgated a series of traffic regulations:

  1. Residents have to travel on fish!

  2. Residents need to feed the fish before you start your trip!The amount of food you feed the fish should be exactly the total distance of your journey.

  3. What kind of food to feed depends on the total distance of your journey!Total distance is a multiple of three. You should feed the fish with Durian. Total distance modulus $3$ equaling $1$. It should be Papaya.Total distance modulus $3$ equaling $2$. It should be Avocado!!!

Sure, fish like to eat these fruits very much.

Today is the first day of the king's decree. Because the residents here are not good at mathematics, they don't know how much fruit they need to give fish to go to other cities. So the king give an order to the energy minister Ynaonlctrm From all cities to all cities directly, which means that he will make $n*(n-1)$ trips.

For example, A - (5 mile) - B - (5 mile) - C, he needs to run the fish, starting at A, passing B, finally arriving C (papaya 10 kg), also he needs to start at C and end at A (papaya 10 kg). Indirect passage is useless. "I've passed City B, my dear emperor." "Oh! It's no use! Not directly! People in cities will never know how much the fish need to eat! The fish will surely die!!! You also need to take several trips which start at B or end with B!" The Emperor said.

It's really a tough task. Can you help him figure out how much fruit he needs to prepare for the emperor's mission?

Input

Multiple input!

Fist line is $N$. next $N-1$ line has three integer $a$, $b$ and $c$. It represent city $a$ and city $b$ is connected by a road of $c$ nautical miles. ($1<n \le 10^4$, $0 \le a,b<n$, $1 \le c<10^5$, $\sum{n} \le 10^5$)

Output

For each data, output three number, the amount of Durian, Papaya and Avocado he need. (the result could be very large, please output the result mod $10^9+7$)

样例输入

5
0 1 2
0 2 3
0 3 7
0 4 6

样例输出

54 60 30

想挑战这道题吗

  • main.c