#include #include #include using namespace std; const int kMAX_V = 60 * 2; struct BipartiteMatching { int V; // 頂点数 vector graph[kMAX_V]; // グラフの隣接リスト表現 int match[kMAX_V]; // 各頂点ごとのマッチングの対応 bool used[kMAX_V]; // DFSの際に使用 BipartiteMatching() { } void Init(int v) { V = v; } // uとvを連結にする void AddEdge(int u, int v) { graph[u].push_back(v); graph[v].push_back(u); } bool DFS(int v) { used[v] = true; for (int i = 0; i < graph[v].size(); i++) { int u = graph[v][i], w = match[u]; if (w < 0 || (!used[w] && DFS(w))) { match[v] = u; match[u] = v; return true; } } return false; } // 二部マッチングを解く int Solve() { int res = 0; memset(match, -1, sizeof(match)); for (int v = 0; v < V; v++) { if (match[v] < 0) { memset(used, sizeof(used), false); if (DFS(v)) { res++; } } } return res; } }; int N; BipartiteMatching BM; int main() { cin >> N; BM.Init(N * 2); for (int i = 0; i < N; i++) { int a; cin >> a; for (int j = 0; j < N; j++) { if (j == a) continue; BM.AddEdge(i, N + j); } } if (BM.Solve() == N) { for (int i = 0; i < N; i++) { cout << BM.match[i] - N << endl; } } else { cout << -1 << endl; } }