CF1369E.DeadLee
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 wi 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 xi and yi (xi=yi).
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 xi nor yi), he will eat Lee instead ×_×.
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.
Lee 为晚餐买了一些食物,但 Lee 的朋友们吃晚饭的方式却十分致命。Lee 非常害怕,他可不想死——至少不想在看到 Online IOI 2020 之前死去……
一共有 n 种不同的食物,以及 m 位 Lee 最要好的朋友。Lee 拥有第 i 种食物共 wi 盘;而每位朋友各有两种最喜爱的食物类型:第 i 位朋友最喜爱的食物类型是 xi 和 yi(其中 xi=yi)。
Lee 将依次呼叫他的朋友们。被呼叫的朋友会前往厨房,并尝试各取一盘自己最喜爱的两种食物(即分别取一盘第 xi 类和一盘第 yi 类食物)。每位朋友恰好只去厨房一次。
唯一的问题在于:如果某位朋友成功吃到了至少一盘食物(总共),那么他就无害;但如果厨房里已没有任何他喜爱的食物剩下(即第 xi 类和第 yi 类食物均已耗尽),他就会把 Lee 吃掉 ×_×。
Lee 可以自行决定呼叫朋友的顺序,因此他想判断自己能否在晚餐中幸存下来;此外,他还想知道具体的呼叫顺序。
输入格式
The first line contains two integers n and m (2≤n≤105; 1≤m≤2⋅105) — the number of different food types and the number of Lee's friends.
The second line contains n integers w1,w2,…,wn (0≤wi≤106) — the number of plates of each food type.
The i-th line of the next m lines contains two integers xi and yi (1≤xi,yi≤n; xi=yi) — the favorite types of food of the i-th friend.
第一行包含两个整数 n 和 m(2≤n≤105;1≤m≤2⋅105)—— 分别表示食物种类的数量以及 Lee 的朋友数量。
第二行包含 n 个整数 w1,w2,…,wn(0≤wi≤106)—— 表示每种食物的盘数。
接下来的 m 行中,第 i 行包含两个整数 xi 和 yi(1≤xi,yi≤n;xi=yi)—— 表示第 i 位朋友最喜爱的两种食物类型。
输出格式
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.
如果李能挺过晚餐,则输出 ALIVE(不区分大小写),否则输出 DEAD(不区分大小写)。
此外,若他能挺过晚餐,请输出李应呼叫朋友的顺序。若存在多种合法顺序,输出任意一种即可。
输入输出样例
输入#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.
在第一个例子中,以下任意一种朋友的顺序都是正确的:[1,3,2]、[3,1,2]、[2,3,1]、[3,2,1]。
在第二个例子中,Lee 应首先给第二位朋友打电话(该朋友将吃掉第 1 种食物的一份),然后再给第一位朋友打电话(该朋友将吃掉第 2 种食物的一份)。如果 Lee 先给第一位朋友打电话,则第一位朋友将吃掉第 1 种和第 2 种食物各一份,导致第二位朋友没有剩余食物可吃。
输入解题思路,AI测评打分。不知道怎么写?