##Description
你需要构造一个1~n的排列,使得它满足m个条件,每个条件形如(ai,bi),表示ai必须在bi前面。在此基础上,你需要使它的字典序最小。
##Input
第一行两个正整数n,m。接下来m行每行两个数ai,bi。
##Output
输出一行n个整数表示答案。如果不存在这样的排列,输出-1。
##Sample Input
5 4
5 4
5 3
4 2
3 2
##Sample Output
1 5 3 4 2
##Data Constraint
对于20%的数据,n,m<=10。
对于40%的数据,n,m<=200。
对于60%的数据,n,m<=1000。
对于100%的数据,n,m<=100000。
##题解
这题是在简单,
如果不考虑字典序,就随便搞一个拓扑序就好了。
如果要字典序最小,
那么每次选就选能选中最小的那个。
用优先队列维护。
##code
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#define N 100003
using namespace std;
char ch;
void read(int& n)
{
n=0;
ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while('0'<=ch && ch<='9')n=(n<<1)+(n<<3)+ch-'0',ch=getchar();
}
void write(int x)
{
if(x>9)write(x/10);
putchar(x%10+48);
}