#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 200006 //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedeflonglong ll; int n , m , k; int A[MAXN];
vi G[MAXN]; priority_queue<int> Qmn , Qmx; int deg[MAXN];
voidsolve(){ cin >> n >> m >> k; rep( i , 1 , m ) { int u , v; scanf("%d%d",&u,&v); G[u].pb( v ); ++ deg[v]; } rep( i , 1 , n ) if( !deg[i] ) Qmn.push( -i ); vi as; int las = 0; vector<pii> ed; while( !Qmn.empty() || !Qmx.empty() ) { while( Qmn.size() && k && ( Qmn.size() > 1 || ( Qmx.size() && -Qmn.top() < Qmx.top() ) ) ) Qmx.push( -Qmn.top() ) , Qmn.pop() , -- k; int u; if( Qmn.size() ) u = -Qmn.top() , Qmn.pop(); else { u = Qmx.top() , Qmx.pop(); ed.eb( mp( las , u ) ); } as.pb( u ); for( int v : G[u] ) { -- deg[v]; if( !deg[v] ) Qmn.push( -v ); } las = u; } for( int x : as ) printf("%d ",x); puts(""); cout << ed.size() << endl; for( auto t : ed ) printf("%d %d\n",t.fi,t.se); }