Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <bits/stdc++.h>
- using namespace std;
- const int OO = 1e9;
- const double EPS = 1e-9;
- vector<vector<int>> graph;
- int n,m;
- vector<bool> vis;
- int v_cnt = 0;
- void dfs(int curr, int ex) {
- vis[curr] = 1;
- v_cnt++;
- for(int e : graph[curr]) {
- if(e != ex && !vis[e]) {
- dfs(e,ex);
- }
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- int t = 10;
- while(t--) {
- cin >> n >> m;
- graph.clear();
- graph.resize(n);
- vis.resize(n);
- for(int i = 0; i < m; i++) {
- int a,b;
- cin >> a >> b;
- a--,b--;
- graph[a].push_back(b);
- }
- vector<int> ans;
- for(int i = 0; i < n; i++) {
- vis.assign(n,0);
- v_cnt = 0;
- dfs(0,i);
- if(v_cnt != n-1) {
- ans.push_back(i+1);
- }
- }
- cout << ans.size() << "\n";
- for(int i = 0; i < ans.size(); i++) {
- if(i)
- cout << " ";
- cout << ans[i];
- }
- cout << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement