307531: CF1369E. DeadLee

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

DeadLee

题意翻译

Lee 为客人们准备了 $n$ 种菜品,其中第 $i$ 种菜品有 $w_i$ 份。Lee 有 $m$ 位客人,每位客人都喜欢吃恰好两种菜品,第 $i$ 位客人喜欢的菜品种类为 $x_i,y_i$。 Lee 的客人们将排成一队依次用餐。对于当前用餐的客人,对于所有他喜欢且还有剩余的菜品,这位客人会吃掉一份该菜品。如果他喜欢的所有种类都已经吃完了,他会愤怒地把 Lee 吃掉。 Lee 希望你帮他安排客人的次序来保证自己的生命安全,或者说明 Lee 一定会被吃掉。 $n \le 10^5, m \le 2 \cdot 10^5, 0 \le w_i \le 10^6$ _Translated by Caro23333_

题目描述

Lee bought some food for dinner time, but Lee's friends eat dinner in a deadly way. Lee is so scared, he doesn't want to die, at least not before seeing Online IOI 2020... There are $ n $ different types of food and $ m $ Lee's best friends. Lee has $ w_i $ plates of the $ i $ -th type of food and each friend has two different favorite types of food: the $ i $ -th friend's favorite types of food are $ x_i $ and $ y_i $ ( $ x_i \ne y_i $ ). Lee will start calling his friends one by one. Whoever is called will go to the kitchen and will try to eat one plate of each of his favorite food types. Each of the friends will go to the kitchen exactly once. The only problem is the following: if a friend will eat at least one plate of food (in total) then he will be harmless. But if there is nothing left for him to eat (neither $ x_i $ nor $ y_i $ ), he will eat Lee instead $ \times\_\times $ . Lee can choose the order of friends to call, so he'd like to determine if he can survive dinner or not. Also, he'd like to know the order itself.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ m $ ( $ 2 \le n \le 10^5 $ ; $ 1 \le m \le 2 \cdot 10^5 $ ) — the number of different food types and the number of Lee's friends. The second line contains $ n $ integers $ w_1, w_2, \ldots, w_n $ ( $ 0 \le w_i \le 10^6 $ ) — the number of plates of each food type. The $ i $ -th line of the next $ m $ lines contains two integers $ x_i $ and $ y_i $ ( $ 1 \le x_i, y_i \le n $ ; $ x_i \ne y_i $ ) — the favorite types of food of the $ i $ -th friend.

输出格式


If Lee can survive the dinner then print ALIVE (case insensitive), otherwise print DEAD (case insensitive). Also, if he can survive the dinner, print the order Lee should call friends. If there are multiple valid orders, print any of them.

输入输出样例

输入样例 #1

3 3
1 2 1
1 2
2 3
1 3

输出样例 #1

ALIVE
3 2 1

输入样例 #2

3 2
1 1 0
1 2
1 3

输出样例 #2

ALIVE
2 1

输入样例 #3

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

输出样例 #3

ALIVE
1 3 2 4

输入样例 #4

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

输出样例 #4

ALIVE
5 4 1 3 2

输入样例 #5

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

输出样例 #5

DEAD

说明

In the first example, any of the following orders of friends are correct : $ [1, 3, 2] $ , $ [3, 1, 2] $ , $ [2, 3, 1] $ , $ [3, 2, 1] $ . In the second example, Lee should call the second friend first (the friend will eat a plate of food $ 1 $ ) and then call the first friend (the friend will eat a plate of food $ 2 $ ). If he calls the first friend sooner than the second one, then the first friend will eat one plate of food $ 1 $ and food $ 2 $ and there will be no food left for the second friend to eat.

Input

题意翻译

Lee 为客人们准备了 $n$ 种菜品,其中第 $i$ 种菜品有 $w_i$ 份。Lee 有 $m$ 位客人,每位客人都喜欢吃恰好两种菜品,第 $i$ 位客人喜欢的菜品种类为 $x_i,y_i$。 Lee 的客人们将排成一队依次用餐。对于当前用餐的客人,对于所有他喜欢且还有剩余的菜品,这位客人会吃掉一份该菜品。如果他喜欢的所有种类都已经吃完了,他会愤怒地把 Lee 吃掉。 Lee 希望你帮他安排客人的次序来保证自己的生命安全,或者说明 Lee 一定会被吃掉。 $n \le 10^5, m \le 2 \cdot 10^5, 0 \le w_i \le 10^6$ _Translated by Caro23333_

加入题单

算法标签: