-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12843.cpp
83 lines (80 loc) · 1.21 KB
/
12843.cpp
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
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstring>
#include <stack>
using namespace std;
int N, M;
int dup[2001][2001];
vector<int> cs;
vector<int> sw;
vector<int> node[2001];
int result;
bool visited[2001];
int select[2001];
bool dfs(int now)
{
if (visited[now])
{
return false;
}
visited[now] = true;
for (int i = 0; i < node[now].size(); i++)
{
int nxt = node[now][i];
/*if (dup[now][nxt] == 1)
{
continue;
}*/
if (select[nxt] == 0 || dfs(select[nxt]))
{
select[nxt] = now;
return true;
}
}
return false;
}
int abc()
{
for (int i = 0; i < cs.size(); i++)
{
memset(visited, false, sizeof(visited));
if (dfs(cs[i]))
{
result++;
}
}
return result;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int i = 1; i <= N; i++)
{
int n;
char c;
cin >> n >> c;
if (c == 'c')
{
cs.push_back(n);
}
else if (c == 's')
{
sw.push_back(n);
}
}
for (int i = 1; i <= M; i++)
{
int a, b;
cin >> a >> b;
node[a].push_back(b);
node[b].push_back(a);
}
cout << N - abc();
}