-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathc.py
executable file
·52 lines (52 loc) · 1.06 KB
/
c.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
# https://codeforces.com/contest/1056/problem/C
import sys
n,m=map(int,input().split())
p=[int(x) for x in input().split()]
ps=[(x,i) for i,x in enumerate(p)]
ps.sort(reverse=True)
x={}
y=[]
s=[False]*(2*n)
for _ in range(m):
a,b=map(int,input().split())
a-=1
b-=1
x[a]=b
x[b]=a
y.append((a,b))
t=int(input())
u=None
if t==2:
u=int(input())-1
if u==-2: import sys;sys.exit(0)
s[u]=True
k=0
l=0
for o in range(n):
if u is not None and u in x and not s[x[u]]:
i=x[u]
elif l<len(y):
i=None
while l<len(y):
a,b=y[l]
l+=1
if s[a]: continue
i = a if p[a]>p[b] else b
break
if i is None:
while True:
_,i=ps[k]
if s[i]: k+=1
else: break
else:
while True:
_,i=ps[k]
if s[i]: k+=1
else: break
s[i]=True
print(i+1)
if o==n-1 and t==2: break
u=int(input())-1
if u==-2: import sys;sys.exit(0)
s[u]=True