// yukicoder: No.241 出席番号(1) // 2019.4.14 bal4u // 最大2部マッチング #include #include //// 高速入力 #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() // 非負整数の入力 { int n = 0, c = gc(); // while (isspace(c)) c = gc(); do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0'); return n; } void out(int n) // 非負整数の表示(出力) { int i; char b[20]; if (!n) pc('0'); else { i = 0; while (n) b[i++] = n % 10 + '0', n /= 10; while (i--) pc(b[i]); } pc('\n'); } //// 最大2部マッチング #define MAX 105 int hi[MAX], to[MAX][MAX]; char seen[MAX]; int match[MAX]; int bpm(int u) { int i, v; for (i = 0; i < hi[u]; i++) { v = to[u][i]; if (seen[v]) continue; seen[v] = 1; if (match[v] < 0 || bpm(match[v])) { match[u] = v, match[v] = u; return 1; } } return 0; } int bipartiteMatching(int m, int n) { int u, max; memset(match, -1, (m + n) * sizeof(int)); max = 0; for (u = 0; u < m; u++) { memset(seen, 0, m + n); if (bpm(u)) max++; } return max; } int main() { int i, j, a, N; N = in(); for (i = 0; i < N; i++) { a = in(); for (j = 0; j < N; j++) if (j != a) to[i][hi[i]++] = N + j; } if (bipartiteMatching(N, N) != N) { puts("-1"); return 0; } for (i = 0; i < N; i++) out(match[i] - N); return 0; }