fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MAXN = 105;
  5. vector<int> adj[MAXN];
  6. bool visited[MAXN];
  7. int n, m, u, v;
  8. int dem_dinh_that = 0;
  9.  
  10. void dfs(int node, int blocked) {
  11. if (node == blocked) return;
  12. visited[node] = true;
  13. for (int neighbor : adj[node]) {
  14. if (!visited[neighbor]) {
  15. dfs(neighbor, blocked);
  16. }
  17. }
  18. }
  19.  
  20. bool la_dinh_that(int s) {
  21. fill(visited, visited + n + 1, false);
  22. dfs(u, s);
  23. return !visited[v];
  24. }
  25.  
  26. int main() {
  27. cin >> n >> m >> u >> v;
  28. for (int i = 0; i < m; i++) {
  29. int a, b;
  30. cin >> a >> b;
  31. adj[a].push_back(b);
  32. adj[b].push_back(a);
  33. }
  34.  
  35. vector<int> dinh_that;
  36. for (int s = 1; s <= n; s++) {
  37. if (s != u && s != v && la_dinh_that(s)) {
  38. dinh_that.push_back(s);
  39. dem_dinh_that++;
  40. }
  41. }
  42.  
  43. cout << dem_dinh_that << endl;
  44. for (int s : dinh_that) {
  45. cout << s << " ";
  46. }
  47. if (dem_dinh_that > 0) cout << endl;
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.01s 5288KB
stdin
6 7 1 6
1 2
2 3
2 4
3 4
3 5
4 5
5 6

stdout
2
2 5