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