• محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Nader Shah Afshar was one of the most powerful rulers in Iran. He won many battles, such as the battle of Herat, Mihmandust, and Kirkuk. During his ruling, Mashhad was Iran’s capital. Each year, he planned an attack on a new country, and annexed it to Iran’s territory. As Nader Shah’s past victories were known to everyone, the country under attack was surrendering the battle without any combat. Therefore, after some years, Iran’s territory was expanded to n new countries.

There was a connected road network between the countries. All roads were two-way passing. Nader Shah only attacked those countries which had at least one road to Iran’s territory at the moment. After capturing each country, Nader Shah chose exactly one road between the captured country and Iran’s territory at that moment, and put Iran flag on it at every one kilometer. In order to make costs as minimal as possible, he chose the shortest road as it needed less Iran flags (if there are more than one shortest road, he arbitrarily chose one of them). These roads were called Afshari roads. Obviously, by choosing the roads this way, there are exactly k1k - 1 Afshari roads when Iran’s territory consists of kk countries.

Several years later, we have received a map of Iran’s territory at the end of Nader Shah’s life. The map has all the road network on it with their lengths in kilometers. Afshari roads are marked in the map. There are nn countries on the map, mm roads connecting them, and n1n - 1 of those roads marked as Afshari. Each country is marked by a distinct number 1xn1 \leq x \leq n. We do not distinguish between the numbers and the countries.

Given the map described above, we want to know the possible country corresponding to Iran and the order by which Nader Shah captured countries. One possible answer can be shown as a1,a2,,ana_1, a_2, \dots , a_n where a1a_1 corresponds to Iran, a2a_2 is the first country that Nader Shah captured, a3a_3 is the second country he captured, and so on. We want to know the lexicographically minimum possible answer. Array x1,x2,,xnx_1, x_2, \dots , x_n is lexicographically smaller than y1,y2,,yny_1, y_2, \dots , y_n if and only if there exists a number ii (1in1 \leq i \leq n) that (x1=y1)(x2=y2)(xi1=yi1)(x_1 = y_1) \land (x_2 = y_2) \land \dots \land (x_{i-1} = y_{i-1}) and xi<yix_i \lt y_i. .

ورودی

The first line of the input contains two integers nn and mm (1n1,000,n1m5,0001 \leq n \leq 1, 000, n - 1 \leq m \leq 5, 000) where nn and mm are the number of countries and the number of roads in the map (the road network), respectively. The next mm lines describe the road network; each line contains four integers u,v,w,u, v, w, and rr (1u,vn,1w106,1 \leq u, v \leq n, 1 \leq w \leq 10^6, and r0,1r \in {0, 1}) which indicate there is a road between uu and vv with the length of ww kilometers, and rr denotes whether the road is Afshari or not. The road is Afshari if and only if r=1r = 1. There is at most one road between two countries. It is guaranteed that there are exactly n1n - 1 Afshari roads in the road network, and all n countries are connected through these n1n - 1 roads.

خروجی

If there is no answer to the problem, print Wrong Map!. Otherwise, write the lexicographically minimum answer to the problem

مثال

ورودی نمونه ۱

3 3
1 2 2 1
2 3 2 1
1 3 1 0
Plain text

خروجی نمونه ۱

Wrong Map!
Plain text

ورودی نمونه ۲

3 3
1 2 1 1
2 3 2 0
1 3 3 1
Plain text

خروجی نمونه ۲

1 3 2
Plain text

ارسال پاسخ برای این سؤال
فایلی انتخاب نشده است.