Cách đọc test đầu vào Python
Link Đề:https://codeforces.com/problemset/problem/1369/F
Code:
Code:
- import itertools as it
- import collections as cc
- import heapq as hp
- import sys
- I=lambda : list(map(int,input().split()))
- import operator as op
- from functools import reduce
- n,m=I()
- w=I()
- de=[0]*n
- for i in range(n):
- de[i]=[0]
- pre=[0]*m
- visi=[0]*m
- for i in range(m):
- x,y=I()
- x-=1;y-=1
- pre[i]=[x,y]
- de[x][0]+=1
- de[y][0]+=1
- de[x].append(i)
- de[y].append(i)
- an=[]
- te=[]
- ans=[]
- for i in range(n):
- if de[i][0]<=w[i]:
- te.append(i)
- while len(te)>0:
- tem=te.pop()
- for i in range(1,len(de[tem])):
- fr=de[tem][i]
- if not visi[fr]:
- visi[fr]=1
- ans.append(fr+1)
- fo=pre[fr][0]+pre[fr][1]-tem
- de[fo][0]-=1
- if de[fo][0]==w[fo]:
- te.append(fo)
- if len(ans)==m:
- print("ALIVE")
- print(*ans[::-1])
- else:
- print("DEAD")
Nhận xét
Đăng nhận xét