fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector <int> adj[100001];
  5. int vis[100001];
  6. int col[100001];
  7.  
  8. void initialise(int V){
  9. for (int i=0; i<V; i++){
  10. adj[i].clear();
  11. }
  12. memset(vis,0,sizeof(vis[0])*V);
  13. memset(col,0,sizeof(col[0])*V);
  14. }
  15.  
  16. void addEdge(int m, int n){
  17. adj[m].push_back(n);
  18. adj[n].push_back(m);
  19. }
  20.  
  21. bool dfs(int node, int color){
  22. vis[node] = 1;
  23. col[node] = color;
  24. for (int child : adj[node]){
  25. if (!vis[child]){
  26. if (dfs(child, color ^ 1) == false){
  27. return false;
  28. }
  29. }
  30. else{
  31. if (col[child] == col[node]){
  32. return false;
  33. }
  34. }
  35. }
  36. return true;
  37. }
  38.  
  39. int main(){
  40. int T; cin >> T;
  41. for (int i=1; i<=T; i++){
  42. int V, E; //vertices and edges
  43. cin >> V >> E;
  44. for (int i=0; i<E; i++){
  45. int m,n;
  46. cin >> m >> n;
  47. addEdge(m,n);
  48. }
  49. bool flag = true;
  50. for (int i = 0; i<V; i++){
  51. if (!vis[i]){
  52. bool res = dfs(i,0);
  53. if (res == false){
  54. flag = false;
  55. }
  56. }
  57. }
  58. cout << "Scenario #" << i << ":" << "\n";
  59. if (flag == false){
  60. cout << "Suspicious bugs found!" << endl;
  61. }
  62. else{
  63. cout << "No suspicious bugs found!" << endl;
  64. }
  65. initialise(V);
  66. }
  67. return 0;
  68. }
  69.  
Success #stdin #stdout 0s 5776KB
stdin
2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
stdout
Scenario #1:
Suspicious bugs found!
Scenario #2:
No suspicious bugs found!