General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
42144572 Practice:
uncle_chips
770C - 55 Python 3 Runtime error on test 4 452 ms 13588 KB 2018-08-27 11:03:12 2018-08-27 11:03:12
→ Source
import sys
flag=True
sys.setrecursionlimit(2000000)
c=[];st=[];
def topo(s):
	global c,st,flag;
	c[s]=1;
	for i in adjli[s]:
		if c[i]==0:
			topo(i)
		if c[i]==1:
			flag=False
	st.append(str(s))
	c[s]=2

try:
	n,k=map(int,input().split(' '))
	main=list(map(int,input().split(' ')))
	depen=[]
	for i in range(n):
		depen.append(list(map(int,input().split(' ')))[1:]);c.append(0)
	c.append(0)
	#print(depen,"depen")
	adjli=[]
	adjli.append(main)
	for i in range(len(depen)):
		adjli.append(depen[i])
	topo(0);st.pop(-1)
	#print(adjli,"adjli")
	if flag:
		print(len(st))
		print(' '.join(st))
	else:
		print(-1)
except Exception as e:
	print(e,"error")
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details