structEdge { int to, next; } e[maxn * 2]; int c1, head[maxn], in[maxn]; inlinevoidadd_edge(int u, int v){ e[c1].to = v; ++in[v]; e[c1].next = head[u]; head[u] = c1++; }
int id[maxn], cnt; voidtopsort(){ queue<int> Q; for (int i = 1; i <= n; ++i) if (!in[i]) Q.push(i); while (!Q.empty()) { int u = Q.front(); Q.pop(); id[u] = ++cnt; for (int i = head[u]; ~i; i = e[i].next) { int v = e[i].to; if (--in[v] == 0) Q.push(v); } } }
intmain(){ fill(head, head + maxn, -1); ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> m; for (int i = 1; i <= m; ++i) { int x, y; cin >> x >> y; a[x] = y; } stack<int> S; for (int i = 1; i <= n; ++i) { if (!a[i]) { if (!S.empty()) add_edge(S.top(), i); S.push(i); } else { if (S.size() + 1 < a[i]) returncout << -1 << "\n", 0; while (S.size() + 1 > a[i]) { add_edge(i, S.top()); S.pop(); } if (!S.empty()) add_edge(S.top(), i); S.push(i); } } topsort(); for (int i = 1; i <= n; ++i) cout << id[i] << " \n"[i == n]; return0; }