def parse(inFile):
N = inFile.getInt()
return [[z - 1 for z in inFile.getInts()[1:]] for k in xrange(N)]
def solve(dependents):
N = len(dependents)
for i in xrange(N):
dep = [False] * N
q = [i]
while (len(q)):
for j in dependents[q.pop()]:
if (dep[j]):
return "Yes"
dep[j] = True
q.append(j)
return "No"
if __name__ == "__main__":
from GCJ import GCJ
GCJ(parse, solve, "/Users/lpebody/gcj/setup/", "a").run()
ZGVmIHBhcnNlKGluRmlsZSk6CiAgICBOID0gaW5GaWxlLmdldEludCgpCiAgICByZXR1cm4gW1t6IC0gMSBmb3IgeiBpbiBpbkZpbGUuZ2V0SW50cygpWzE6XV0gZm9yIGsgaW4geHJhbmdlKE4pXQoKZGVmIHNvbHZlKGRlcGVuZGVudHMpOgogICAgTiA9IGxlbihkZXBlbmRlbnRzKQogICAgZm9yIGkgaW4geHJhbmdlKE4pOgogICAgICAgIGRlcCA9IFtGYWxzZV0gKiBOCiAgICAgICAgcSA9IFtpXQogICAgICAgIHdoaWxlIChsZW4ocSkpOgogICAgICAgICAgICBmb3IgaiBpbiBkZXBlbmRlbnRzW3EucG9wKCldOgogICAgICAgICAgICAgICAgaWYgKGRlcFtqXSk6CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuICJZZXMiCiAgICAgICAgICAgICAgICBkZXBbal0gPSBUcnVlCiAgICAgICAgICAgICAgICBxLmFwcGVuZChqKQogICAgcmV0dXJuICJObyIKCmlmIF9fbmFtZV9fID09ICJfX21haW5fXyI6CiAgICBmcm9tIEdDSiBpbXBvcnQgR0NKCiAgICBHQ0oocGFyc2UsIHNvbHZlLCAiL1VzZXJzL2xwZWJvZHkvZ2NqL3NldHVwLyIsICJhIikucnVuKCkK