Codeforces-1369-E. DeadLee(拓扑+贪心)

E. DeadLee

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.

Input

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.

Output

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.

Examples

input

3 3
1 2 1
1 2
2 3
1 3

output

ALIVE
3 2 1 

input

3 2
1 1 0
1 2
1 3

output

ALIVE
2 1 

input

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

output

ALIVE
1 3 2 4 

input

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

output

ALIVE
5 4 1 3 2 

input

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

output

DEAD

Note

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.

解题思路:

比赛的时候答案都已经呼之欲出了。就差最后的输出没有倒序输出!!就差亿点点。

设一个盘菜x有i个人想吃,那么令x的入度为 i。
题目有解的起始条件显然是有至少一盘菜可以满足所有想吃的人要求,也就是a[x] >= in[x]。
那么就让这盘菜被吃吧。然后吃掉这盘菜的人,另一盘菜就大可不必去吃了。
所以把另一盘菜的入度减1。当另一盘才也满足a[x] >= in[x]时又入队。其实就是拓扑排序。
关键的一点是,要倒序输出。

AC代码:

#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define pd(n) print f("%d\n", n)
#define pc(n) print f("%c", n)
#define pdd(n,m) print f("%d %d", n, m)
#define pld(n) print f("%int d\n", n)
#define pldd(n,m) print f("%int d %int d\n", n, m)
#define sld(n) scanf("%int d",&n)
#define sldd(n,m) scanf("%int d%int d",&n,&m)
#define slddd(n,m,k) scanf("%int d%int d%int d",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sc(n) scanf("%c",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define rep(i,a,n) for(int  i=a;i<=n;i++)
#define per(i,a,n) for(int  i=n;i>=a;i--)
#define mem(a,n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define aint (x) (x).begin(),(x).end()
#define fi first
#define se second
#define mod(x) ((x)%MOD)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
#define pii map<int ,int >
#define mk make_pair
#define rtl rt<<1
#define rtr rt<<1|1
#define Max(x,y) (x)>(y)?(x):(y)
#define int long long


typedef pair<int ,int > PII;
typedef long long ll;
typedef unsigned long long uint ;
typedef long double ld;
const int  MOD = 1e9 + 7;
const int  mod = 1e9 + 7;
const double eps = 1e-9;
const int  INF = 0x3f3f3f3f3f3f3f3f;
//const int  inf = 0x3f3f3f3f;
inline int  read(){int  ret = 0, sgn = 1;char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-')sgn = -1;ch = getchar();}
while (ch >= '0' && ch <= '9'){ret = ret*10 + ch - '0';ch = getchar();}
return ret*sgn;}
inline void Out(int  a){if(a>9) Out(a/10);putchar(a%10+'0');}
int  qmul(int  a,int  b,int  mod){int  res=0;while(b){if(b&1)res=(res+a)%mod;a=(a+a)%mod;b>>=1;}return res;}
int  qpow(int  m,int  k,int  mod){int  res=1%mod,t=m%mod;while(k){if(k&1)res=qmul(res,t,mod);t=qmul(t,t,mod);k>>=1;}return res;}
int  gcd(int  a,int  b){if(b > a) swap(a,b); return b==0?a : gcd(b,a%b);}
int  lcm(int  a,int  b){return a/gcd(a,b)*b;}
int  inv(int  x,int  mod){return qpow(x,mod-2,mod)%mod;}
//const int  N = 3e3+15;
int  t = 1,cas = 1;
int  n,m;
const int  N = 2e6+7;
int dp[N];
int a[N],ans;
vector<int> G[N];
int in[N];
int vis[N];
int want[N][2];
queue<int> que;
int food[N];
int res[N];
int pos = 0;

signed  main(){
    scanf("%lld%lld",&n,&m);
    for(int i = 0 ; i < n ; i ++){
        scanf("%lld",&a[i]);
    }
    for(int i = 0 ; i < m ; i ++){
        food[i] = -1;
        int x,y;
        scanf("%lld%lld",&x,&y);
        x--;y--;
        in[x]++,in[y]++;
        G[x].pb(i);
        G[y].pb(i);
        want[i][0] =x;
        want[i][1] =y;
    }
    int flag = 0;
    for(int i = 0 ; i < n ; i ++){
        if(in[i] <= a[i]){
            que.push(i);
        }
    }
    //cout<<"-----debug-----"<<endl;
    while(!que.empty()){
        int tmp = que.front();que.pop();
        for(int i = 0 ; i < G[tmp].size() ; i ++){
            int per = G[tmp][i];
            if(food[per] == -1){
                food[per] = tmp;
                res[pos++] = per+1;
                for(int k = 0 ; k < 2 ; k ++){
                    int wt = want[per][k];
                    in[wt] --;
                    if(!vis[wt] && in[wt] <= a[wt]){
                        vis[wt] = 1;
                        que.push(wt);
                    }
                }
            }
        }
    }
    if(pos == m){
        cout<<"ALIVE"<<endl;
        for(int i = m-1 ; i >= 0 ; i  --)
            cout<<res[i]<<" ";
    }
    else{
        cout<<"DEAD"<<endl;
    }

}

已经博主授权,源码转载自 https://pan.quark.cn/s/e577710b7191 ### 解决Win10系统中Word文件图标显示不正常问题 #### 问题描述 在Windows 10操作系统中,部分用户遇到Word文档图标呈现非正常状态的问题。具体表现为:本应展示为Microsoft Word图标的DOC或DOCX文件,在系统中却呈现为常规的文本文件图标。这种现象不仅降低了用户的视觉体验,还可能引发一定的操作不便。 #### 解决方案 ##### 方法一:借助注册表编辑来纠正图标显示异常 1. **进行注册表备份**:为了保障系统的稳定性,在开展任何注册表修改之前,必须对注册表进行备份。可以通过“导出”功能来达成备份目的。 - 启动“运行”对话框(快捷键:`Windows + R`),键入`regedit`,随后按回车键进入注册表编辑界面。 - 在注册表编辑界面中,找到菜单栏里的“文件”选项,点击后选择“导出”,依照提示完成注册表备份。 2. **移除相关注册表项**: - 在`HKEY_CLASSES_ROOT`下,删除以下四个注册表项: - `.doc` - `.docx` - `Word.Document.8` - `Word.Document.12` - 在`HKEY_LOCAL_MACHINE\SOFTWARE\Classes`下,同样移除上述四个注册表项。 3. **重新启动计算机**:执行完上述步骤后,重新启动计算机以使修改生效。 #### 方法二:通过调整文件关联来纠正图标显示异常 如果第一种方法未能解决难题,则可以尝试调整文件的关联方式,具体步骤如下: 1. **移除文件关联**: - 在`HKEY_CLASSES_ROOT`下删除`....
源码直接下载地址: https://pan.quark.cn/s/a4b39357ea24 台达VFD037E43A变频器使用说明书包含了产品的基础安装、操作及维护等方面的全面信息,以下为其知识要点具体阐述: 1. 安全操作注意事项:在操作台达VFD037E43A变频器之前,说明书着重指出必须研读安全信息以保障操作人员与设备的双重安全。使用前应核实电源已切断,防止触碰带电线路,同时对内部电路板的静电防护措施也做了规定。此外,说明书还明确禁止非专业人员擅自改装变频器。 2. 接地规范:说明书说明了230V和460V系列变频器分别遵循第三类接地和特殊接地标准,从而确保了安全接地的合规性。 3. 安装与连接:说明书详尽说明了产品装置、搬运、接线方法、主回路端子及控制回路端子等环节,为用户正确配置和连接变频器提供了指导。 4. 零件选择:说明书内含零件选购参考,协助用户依据实际需求挑选适配的零件。 5. 参数调节:说明书中的“参数索引”及“参数深入解释”部分指导用户如何设定和调整变频器的运行参数。 6. 应用案例:在“成功实施案例”部分,说明书以实例形式向用户展示变频器在不同工作场景下的应用技巧。 7. 问题诊断:说明书提供了“警示代码解析”和“错误代码解析”,帮助用户识别变频器的常见故障并进行排除。 8. 通讯方式:说明书介绍了“CANopen通讯基础”和“BACnet应用指南及流程”,使用户能够掌握如何通过这些通讯方式将变频器融入工业自动化系统。 9. 特殊功能介绍:说明书还收录了“可编程逻辑控制器应用”和“PT100操作指南”,阐述了变频器的可编程逻辑控制器特性及温度传感器操作方法。 10. 网站与升级:说明书指出产品资料如有变动可通过台达电子工业自动化类产品的官方网...
代码下载地址: https://pan.quark.cn/s/a4b39357ea24 ST-Link V2是一种被普遍采用用于调试和编程的工具,其核心应用对象是STMicroelectronics(简称ST)所推出的STM32与STM8微控制器系列。在产品的设计与开发阶段,ST-Link V2占据着不可或缺的地位,它赋予工程师执行代码传输、程序调试以及硬件检测的能力。为了运用该设备,进行ST-Link V2驱动程序的安装是必要的前置工作。针对不同操作系统的环境,驱动程序的安装方式需做出相应的适配。举例来说,若在Windows XP环境下运作,应选择安装"ST-LINKV2USBdriver1.04forWindows7,VistaandXP.zip"这一驱动包;而对于Windows 7或Windows 8系统,则需安装"ST-LINKV2USBdriver1.0forWindows7andWindows8,32and64bits.zip"版本。整个安装流程一般包含以下环节:首先对下载的文件进行解压缩处理,随后双击运行安装文件,依照提示点击"Next"与"Install"按钮,最后通过点击"Finish"来完成安装操作。一旦驱动安装成功,用户应能在设备管理器中查找到ST-Link V2仿真器,且该设备的电源指示灯应呈现持续点亮的状态。关于软件的安装,针对STM32微控制器配备的软件工具是STM32 ST-LINK Utility,而STM8微控制器则采用ST Visual Develop(简称STVD)环境中的ST Visual Programmer(简称STVP)。安装这些软件时,通常需要启动安装程序,并遵循安装向导的步骤来达成整个安装任务。在开展STM32的...
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值