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 criticalCount = 0; // Bi?n d?m s? d?nh th?t
  9.  
  10. void dfs(int node, int blocked) {
  11. if (node == blocked) return; // Không xét d?nh b? ch?n
  12. visited[node] = true;
  13. for (int neighbor : adj[node]) {
  14. if (!visited[neighbor]) {
  15. dfs(neighbor, blocked);
  16. }
  17. }
  18. }
  19.  
  20. bool isCritical(int s) {
  21. fill(visited, visited + n + 1, false);
  22. dfs(u, s); // Th? b? d?nh s và ki?m tra du?ng di t? u d?n v
  23. return !visited[v]; // N?u không d?n du?c v, thì s là d?nh th?t
  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> criticalNodes;
  36. for (int s = 1; s <= n; s++) {
  37. if (s != u && s != v && isCritical(s)) {
  38. criticalNodes.push_back(s);
  39. criticalCount++; // Tang bi?n d?m
  40. }
  41. }
  42.  
  43. cout << criticalCount << endl;
  44. for (int s : criticalNodes) {
  45. cout << s << " ";
  46. }
  47. if (criticalCount > 0) cout << endl;
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.01s 5292KB
stdin
6 7 1 6
1 2
2 3
3 4
3 5
4 5
5 6
stdout
3
2 3 5