#include #include #define REP_(i, a_, b_, a, b, ...) \ for (int i = (a), END_##i = (b); i < END_##i; ++i) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define ALL(x) std::begin(x), std::end(x) using i64 = long long; template inline bool chmax(T &a, U b) { return a < b and ((a = std::move(b)), true); } template inline bool chmin(T &a, U b) { return a > b and ((a = std::move(b)), true); } template inline int ssize(const T &a) { return (int) std::size(a); } template std::istream &operator>>(std::istream &is, std::vector &a) { for (auto &x : a) is >> x; return is; } template std::ostream &operator<<(std::ostream &os, const std::pair &a) { return os << "(" << a.first << ", " << a.second << ")"; } template std::ostream &print_seq(const Container &a, std::string_view sep = " ", std::string_view ends = "\n", std::ostream &os = std::cout) { auto b = std::begin(a), e = std::end(a); for (auto it = std::begin(a); it != e; ++it) { if (it != b) os << sep; os << *it; } return os << ends; } template struct is_iterable : std::false_type {}; template struct is_iterable())), decltype(std::end(std::declval()))>> : std::true_type { }; template::value && !std::is_same::value && !std::is_same::value>> std::ostream &operator<<(std::ostream &os, const T &a) { return print_seq(a, ", ", "", (os << "{")) << "}"; } void print() { std::cout << "\n"; } template void print(const T &x) { std::cout << x << "\n"; } template void print(const Head &head, Tail... tail) { std::cout << head << " "; print(tail...); } void read_from_cin() {} template void read_from_cin(T &value, Ts &...args) { std::cin >> value; read_from_cin(args...); } #define INPUT(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__) #ifdef MY_DEBUG #include "debug_dump.hpp" #else #define DUMP(...) #endif using namespace std; auto solve() -> optional> { INPUT(int, n); atcoder::mf_graph g(n + n + 2); int kSource = 2 * n; int kSink = 2 * n + 1; REP(i, n) { g.add_edge(kSource, i, 1); g.add_edge(n + i, kSink, 1); } REP(i, n) { INPUT(int, a, b); --a, --b; g.add_edge(i, n + a, 1); if (a != b) g.add_edge(i, n + b, 1); } auto mf = g.flow(kSource, kSink, n); DUMP(mf); if (mf != n) return nullopt; vector ans(n); for (const auto &e : g.edges()) { if (e.from == kSource or e.to == kSink) continue; if (e.flow != 1) continue; int i = e.from; int j = e.to - n + 1; ans[i] = j; } return ans; } int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); auto ans = solve(); if (not ans) { print("No"); } else { print("Yes"); print_seq(ans.value(), "\n"); } }