Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <vector>
- #include <deque>
- #define se second
- #define fi first
- #define mp make_pair
- #define pb push_back
- using namespace std;
- int n, m;
- vector<vector<int>> g;
- vector<bool> used;
- bool cycle;
- void dfs(int h) {
- used[h] = true;
- for (auto e : g[h]) {
- if (used[e]) {
- cycle = true;
- return;
- }
- if (!used[e]) dfs(e);
- }
- }
- int main() {
- cin >> n >> m;
- vector<bool> is_root(n, true);
- for (int i = 0; i < m; i++) {
- int x, y;
- cin >> x >> y;
- x--, y--;
- g[x].pb(y);
- is_root[y] = false;
- }
- used.assign(n, false);
- cycle = false;
- for (int i = 0; i < n; i++) {
- if (!used[i]) dfs(i);
- }
- if (cycle) {
- cout << "No";
- return 0;
- }
- for (int i = 0; i < n; i++) {
- if (is_root[i])
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement