-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLight Oj 1009
106 lines (89 loc) · 1.83 KB
/
Light Oj 1009
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <bits/stdc++.h>
using namespace std;
#define max1 100010
typedef map <int , int> mm;
typedef vector <int> vc;
typedef long long int ll;
vc node[max1];
#define G -1
#define B 1
#define W 0
int x , y;
queue<int> mq;
mm mp;
int grap_col[max1];
int maxi (int d , int p)
{
if(d > p)
return d;
else
return p;
}
void bfs_algo (int source)
{
int u , v;
grap_col[source] = B;
mq.push(source);
while(!mq.empty())
{
u = mq.front();
mq.pop();
for(int i = 0; i < node[u].size(); i++)
{
v = node[u][i];
if(grap_col[v] == G)
{
if(grap_col[u] == B)
{
x++;
grap_col[v] = W;
}
else
{
y++;
grap_col[v] = B;
}
mq.push(v);
}
}
}
}
int main()
{
int tes , o = 0;
cin >> tes;
while(tes--)
{
o++;
int p , a ,b , in = 0;
cin >> p;
mp.clear();
for(int i = 1; i <= p; i++)
{
cin>> a >> b;
if(!mp[a])
{
mp[a] = ++in;
node[mp[a]].clear();
}
if(!mp[b])
{
mp[b] = ++in;
node[mp[b]].clear();
}
node[mp[a]].push_back(mp[b]);
node[mp[b]].push_back(mp[a]);
}
memset(grap_col , G , sizeof grap_col);
ll sum = 0;
for(int i =1; i <= in; i++)
{
if(grap_col[i] != G)
continue;
x = 0 ,y = 1;
bfs_algo(i);
sum = sum + maxi(x , y);
}
printf("Case %d: %lld\n",o , sum);
}
}