
#include <bits/stdc++.h>
using namespace std;
#include<queue>
#include<cstdio>
int a[50][50];
int n;
void bfs(int s)
{
int* b = new int[n + 1];
b[0] = 0;
for (int i = 1; i < n; i++)
{
b[i] = 1;
}
queue<int>q;
q.push(s);
int u;
while (!q.empty())
{
u = q.front();
q.pop();
printf("%d ", u);
for (int v = 0; v < n; v++)
{
if (a[u][v] == 1 && b[v] == 1)
{
q.push(v);
b[v] = 0;
}
else
{
continue;
}
}
}
}
int main()
{
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
scanf("%d", &a[i][j]);
}
}
bfs(0);
puts(" ");
}
}