Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //#include <chrono>
- //#include <fstream>
- //#include <bits/stdc++.h>
- #include <vector>
- #include <list>
- #include <algorithm>
- #define mp make_pair
- #define pb push_back
- #define eb emplace_back
- #define f first
- #define s second
- #define sz(x) (int)x.size()
- #define all(x) begin(x), end(x)
- #define rall(x) rbegin(x), rend(x)
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- typedef pair<int, int> pi;
- typedef pair<ll, ll> pl;
- vector<list<int>> vec;
- vector<char> color;
- vector<int> answ;
- bool dfs(int v) {
- color[v] = 1;
- int count_b = 0;
- int count = 0;
- for (int i : vec[v]) {
- if (color[i] == 0) {
- dfs(i);
- }
- else if (color[i] == 1) {
- cout << "No\n";
- exit(0);
- }
- }
- color[v] = 2;
- answ.pb(v + 1);
- return count == count_b;
- }
- int main() {
- /*ifstream cin("in.txt");
- ofstream cout("out.txt");
- auto start_time = chrono::high_resolution_clock::now();*/
- ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n, m;
- cin >> n >> m;
- vec.assign(n, list<int>());
- color.assign(n, 0);
- for (int i = 0; i < m; i++) {
- int a, b;
- cin >> a >> b;
- vec[--a].eb(--b);
- }
- answ.reserve(n);
- for (int i = 0; i < n; i++) {
- if (!color[i]) {
- if (!dfs(i)) {
- cout << "No" << endl;
- return 0;
- }
- }
- }
- cout << "Yes" << endl;
- reverse(all(answ));
- for (int i : answ)
- cout << i << " ";
- /*auto end_time = chrono::high_resolution_clock::now();
- chrono::duration<double> duration = end_time - start_time;
- cout << duration.count() << "\n";
- cin.close();
- cout.close();*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment