#P6310. 「Wdsr-1」仓库建设

「Wdsr-1」仓库建设

Background

One day, a famine broke out in the Human Village.

Problem Description

Because Gensokyo promotes the idea of a “community with a shared future of Gensokyo”, the kappa decided to help humans build some granaries to prevent famine from happening again.

The Human Village has nn cities and mm bidirectional roads. The ii-th road connects cities uiu_i and viv_i, with length wiw_i units.

Since each city has a different technology level, grain-transport trucks starting from different cities have different fuel capacities. The grain-transport trucks in the ii-th city can only support driving for xix_i units. Of course, cities are friendly to each other: no matter which city the truck arrives at, the enthusiastic local people will refuel it to full.

Kappa technology is highly advanced, so the amount of grain a warehouse can store can be considered infinite. Only warehouses can dispatch grain-transport trucks.

Now choose some cities to build warehouses so that every city can receive grain from a warehouse. To save resources, the kappa want the number of warehouses to be as small as possible.

However, youkai may sometimes occupy a city, so you need to compute the minimum number of warehouses needed when an arbitrary city is not allowed to build a warehouse.

Input Format

The first line contains two integers n,mn, m, with meanings as described above.

The next mm lines each contain 3 integers ui,vi,wiu_i, v_i, w_i, with meanings as described above.

The next line contains nn integers xix_i, with meanings as described above.

Output Format

Output one line with n+1n+1 integers.

The first integer indicates the minimum number of warehouses needed. The next nn integers: the ii-th integer indicates the minimum number of warehouses needed when city ii is not allowed to build a warehouse.

If, when city ii is not allowed to build a warehouse, building warehouses in other cities still cannot reach this city, output -1.

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

Hint

Sample Explanation

This is the graph drawn for the sample. Obviously, building a warehouse in city 3 solves the problem. When city 3 is not allowed to build a warehouse, no matter how you build warehouses in other cities, grain still cannot be transported to city 3, so output -1.


Constraints

For 25%25\% of the testdata, 1n,m1031\le n, m\le 10 ^ 3 is guaranteed.

For another 25%25\% of the testdata, m=n1m=n-1 is guaranteed.

For 100%100\% of the testdata, 1n,m3×1051\le n, m \le 3\times 10^5, 1ui,vin1\le u_i, v_i\le n, 1wi,xi1061\le w_i, x_i\le 10^6 are guaranteed, and the graph is connected.

Translated by ChatGPT 5