#include #include #include using namespace std; int n,m; int Inside[10011]; vector Graph[10011]; int q[10011]; int qL=0; vector ans; int main() { freopen("lottery.in","r",stdin); freopen("lottery.out","w",stdout); int i; int uk=1; int a,b; m=1; scanf("%d",&n); for (i=1;i<=n;i++) { scanf("%d %d",&a,&b); if (a>m) m=a; if (b>m) m=b; Graph[a].push_back(b); Inside[b]++; } for (i=1;i<=m;i++) { if (Inside[i]==0) { qL++; q[qL]=i; } } while(uk<=qL) { ans.push_back(q[uk]); for (i=0;i