#include #include #include #include #include #include using namespace std; typedef int lld; struct QWE { lld ins, vert; bool operator<(const QWE& other)const { return (ins > other.ins); } }; QWE make_Q(lld ins, lld vert) { QWE ret; ret.ins = ins; ret.vert = vert; return ret; } lld n, m; vector Graph[1502]; lld szof[1502]; lld icnt[1502]; priority_queue< QWE > pq; bool gone[1502]; lld cnt=1; pair ans[1502]; int main () { freopen("lottery.in", "r", stdin); freopen("lottery.out", "w", stdout); n=0; scanf("%d", &m); for (lld i=1; i<=m; i++) { lld a, b; scanf("%d %d", &a, &b); Graph[a].push_back(b); szof[b]++; n = max(n, max(a, b)); } for (lld i=1; i<=n; i++) { pq.push(make_Q(szof[i], i)); } while (!pq.empty()) { QWE top; do { top = pq.top(); pq.pop(); } while (gone[top.vert] && !pq.empty()); if (pq.empty()) break; ans[top.vert] = make_pair(cnt++, top.vert); gone[top.vert] = true; for (lld i=0; i