#include #include #include #include #include #include #define REP(i,a,b) for(i=a;ik);if(i>=j)break;t=d[i];d[i]=d[j];d[j]=t;t=m[i];m[i]=m[j];m[j]=t;}intIntSort(d,m,i);intIntSort(d+j+1,m+j+1,s-j-1);} int n; int in[1200][1200], tm[1200][1200], go[1200][1200]; int next[1200], house[1200], htm[1200], fixed[1200]; int res[1200]; int main(){ int i, j; int k, t, h; assert( scanf("%d",&n)==1 ); assert(1<=n && n<=100); rep(i,n) rep(j,n) assert( scanf("%d",in[i]+j)==1 ), assert( in[i][j] > 0 ); rep(i,n){ rep(j,n) tm[i][j] = in[i][j], go[i][j] = j; intIntSort(tm[i], go[i], n); } rep(i,n) next[i] = 0, house[i] = -1, fixed[i] = 0; for(;;){ rep(i,n) if(!fixed[i] && next[i]==n) break; if(i= tm[i][next[i]]) t = tm[i][next[i]], k=i; if(k==-1){ /* every friends are locked */ rep(i,n) res[house[i]] = i; rep(i,n){ if(i) putchar(' '); printf("%d",res[i]+1); } puts(""); break; } h = go[k][next[k]]; /* next move is "friend k goes to house h in time t" */ if(house[h] >= 0 && htm[h] < t){ /* house h has a friend, and he visited before time t, then he escapes from house. instead of that, friend k is locked away */ fixed[house[h]] = 0; fixed[k] = 1; house[h] = k; htm[h] = t; } else if(house[h]==-1) { /* if house h is empty, he is locked away */ fixed[k] = 1; house[h] = k; htm[h] = t; } /* otherwise (house h has a friend, and he visit this house after time t), he may go to next house */ next[k]++; } return 0; }