def func():
def dfs( node ):
print("%d "% (node+1), end = "")
explored[node] = 1
for i in range(0, nodes):
if matrix[node][i] == 1 and explored[i] == 0:
dfs( i )
nodes = int(input())
matrix = []
for i in range(nodes):
line = [int(i) for i in input().split(" ")]
matrix.append(line)
explored = [0] * (nodes+1)
startNode = 1
print("Depth First Search")
dfs( startNode )
func()
ZGVmIGZ1bmMoKToKCiAgICBkZWYgZGZzKCBub2RlICk6CgogICAgICAgIHByaW50KCIlZCAiJSAobm9kZSsxKSwgZW5kID0gIiIpCgogICAgICAgIGV4cGxvcmVkW25vZGVdID0gMQoKICAgICAgICBmb3IgaSBpbiByYW5nZSgwLCBub2Rlcyk6CgogICAgICAgICAgICBpZiBtYXRyaXhbbm9kZV1baV0gPT0gMSBhbmQgZXhwbG9yZWRbaV0gPT0gMDoKCiAgICAgICAgICAgICAgICBkZnMoIGkgKQoKICAgIAogICAgbm9kZXMgPSBpbnQoaW5wdXQoKSkKICAgIAogICAgbWF0cml4ID0gW10KICAgIAogICAgZm9yIGkgaW4gcmFuZ2Uobm9kZXMpOgogICAgCQogICAgCWxpbmUgPSBbaW50KGkpIGZvciBpIGluIGlucHV0KCkuc3BsaXQoIiAiKV0KICAgIAkKICAgIAltYXRyaXguYXBwZW5kKGxpbmUpCiAgICAKICAgIGV4cGxvcmVkID0gWzBdICogKG5vZGVzKzEpCgogICAgc3RhcnROb2RlID0gMQogICAgCiAgICBwcmludCgiRGVwdGggRmlyc3QgU2VhcmNoIikKCiAgICBkZnMoIHN0YXJ0Tm9kZSApCgpmdW5jKCk=
OAowIDEgMSAwIDAgMCAwIDAKMSAwIDEgMSAwIDAgMCAwCjEgMSAwIDEgMSAxIDAgMQowIDEgMSAwIDEgMCAxIDAKMCAwIDEgMSAwIDEgMSAwCjAgMCAxIDAgMSAwIDEgMQowIDAgMCAwIDEgMSAwIDEKMCAwIDEgMCAwIDEgMSAw
8
0 1 1 0 0 0 0 0
1 0 1 1 0 0 0 0
1 1 0 1 1 1 0 1
0 1 1 0 1 0 1 0
0 0 1 1 0 1 1 0
0 0 1 0 1 0 1 1
0 0 0 0 1 1 0 1
0 0 1 0 0 1 1 0