forked from pranavanurag/SPOJSolutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBUGLIFE.cpp
More file actions
80 lines (70 loc) · 1.18 KB
/
Copy pathBUGLIFE.cpp
File metadata and controls
80 lines (70 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define scan(x) scanf("%d", &x)
int N, M;
bool Susp;
struct Node
{
vector <int> Neighbours;
int Gender, Color;
}Graph[2001];
void ClearGraph()
{
for (int i = 0; i <= 2000; i++)
{
Graph[i].Neighbours.clear();
Graph[i].Gender = Graph[i].Color = -1;
}
Susp = false;
}
void DFSVisit(int u)
{
Graph[u].Color = 0;
for (int i = 0; i < Graph[u].Neighbours.size(); i++)
{
int v = Graph[u].Neighbours[i];
if (Graph[v].Color == -1)
{
Graph[v].Gender = !Graph[u].Gender;
DFSVisit(v);
}
else if (Graph[v].Gender == Graph[u].Gender)
Susp = true;
}
Graph[u].Color = 1;
}
void DFS()
{
for (int i = 1; i <= N; i++)
if (Graph[i].Color == -1)
{
Graph[i].Gender = 0;
DFSVisit(i);
}
}
int main()
{
int T;
scan(T);
for (int t = 1; t <= T; t++)
{
ClearGraph();
scan(N);
scan(M);
for (int i = 1; i <= M; i++)
{
int v1, v2;
scan(v1); scan(v2);
Graph[v1].Neighbours.push_back(v2);
Graph[v2].Neighbours.push_back(v1);
}
DFS();
printf("Scenario #%d:\n", t);
if (Susp)
printf("Suspicious bugs found!\n");
else
printf("No suspicious bugs found!\n");
}
return 0;
}