#include #include #include #include #include #include #include #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template void PPPPP(T t) { cerr << t; } template void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #else #define dump(...) do{ } while(false) #endif template vector make_v(size_t a, T b) { return vector(a, b); } template auto make_v(size_t a, Ts... ts) { return vector(a, make_v(ts...)); } template bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; } template bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; } template void print(T a) { cout << a << '\n'; } template void print(T a, Ts... ts) { cout << a << ' '; print(ts...); } template istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on #include template class Dinic { struct Edge { int to, rev; T cap; Edge(int t, int r, T c) : to(t), rev(r), cap(c) {} }; int n; vector level; vector itr; bool bfs(int s, int t) { queue que; level.assign(n, -1); level[s] = 0; que.emplace(s); while (que.size()) { int v = que.front(); que.pop(); for (auto &edge : G[v]) { if (edge.cap > 0 && level[edge.to] == -1) { level[edge.to] = level[v] + 1; que.emplace(edge.to); } } } return level[t] != -1; } T dfs(int v, int t, T flow) { if (v == t) return flow; for (int &i = itr[v]; i < static_cast(G[v].size()); i++) { auto &edge = G[v][i]; if (edge.cap > 0 && level[v] < level[edge.to]) { T d = dfs(edge.to, t, min(flow, edge.cap)); if (d > 0) { edge.cap -= d; G[edge.to][edge.rev].cap += d; return d; } } } return 0; } public: vector> G; Dinic(int _n) { n = _n; G.resize(n); } void add_edge(int s, int t, T cap) { G[s].emplace_back(t, G[t].size(), cap); G[t].emplace_back(s, static_cast(G[s].size() - 1), 0); } T max_flow(int s, int t, T inf) { T ans = 0; while (bfs(s, t)) { itr.assign(n, 0); for (T f = 0; (f = dfs(s, t, inf)) > 0; ans += f) ; } return ans; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin, n; int start = 2 * n, goal = start + 1; Dinic dinic(goal + 1); rep(i, 0, n) { int ng; cin, ng; dinic.add_edge(start, i, 1); dinic.add_edge(i + n, goal, 1); rep(j, 0, n) { if (ng == j) continue; dinic.add_edge(i, j + n, 1); } } int sz = dinic.max_flow(start, goal, n); if (sz == n) { rep(i, 0, n) { for (auto edge : dinic.G[i]) { if (n <= edge.to && edge.to < 2 * n && edge.cap == 0) { print(edge.to - n); break; } } } } else { print(-1); } return 0; }