Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <algorithm>
- #include <limits>
- using namespace std;
- const int NMAX = 103;
- int n, m, k;
- list<int> edges[NMAX];
- bool canArrive[NMAX], vis[NMAX];
- void read() {
- cin >> n >> m >> k;
- for (int i = 0; i < m; i++) {
- int a, b;
- cin >> a >> b;
- edges[a].push_back(b);
- }
- }
- void dfs(int node) {
- canArrive[node] = true;
- for (int it : edges[node]) {
- if (!canArrive[it]) {
- dfs(it);
- }
- }
- }
- int start;
- void dfs2(int node) {
- vis[node] = true;
- for (int it : edges[node]) {
- if (vis[it] && it == start) {
- cout << it << ' ';
- return;
- }
- dfs2(it);
- }
- }
- int main() {
- read();
- dfs(k);
- cout << "orase: ";
- for (int i = 1; i <= n; i++) {
- if (canArrive[i]) {
- fill(vis, vis + n + 1, false);
- start = i;
- dfs2(i);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement