-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountcross.cpp
61 lines (47 loc) · 1.41 KB
/
countcross.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
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
using pi = pair<int, int>;
int n, k, r;
map<pi, set<pi>> roads;
bool cow_at_loc[maxn][maxn];
pi cows[maxn];
bool visited[maxn][maxn];
int c_cows_found = 0;
void f_fill(int x, int y, int parx, int pary) {
if (x < 0 || x >= n || y < 0 || y >= n) return;
if (visited[x][y]) return;
if (roads[{x, y}].find({parx, pary}) != roads[{x, y}].end()) return;
visited[x][y] = true;
if (cow_at_loc[x][y]) c_cows_found++;
f_fill(x + 1, y, x, y);
f_fill(x - 1, y, x, y);
f_fill(x, y + 1, x, y);
f_fill(x, y - 1, x, y);
}
int main(int argc, char const *argv[]) {
ifstream fin("countcross.in");
ofstream fout("countcross.out");
fin >> n >> k >> r;
for (int i = 0; i < r; i++) {
pi a, b;
fin >> a.first >> a.second >> b.first >> b.second;
a.first--, a.second--, b.first--, b.second--;
roads[a].insert(b);
roads[b].insert(a);
}
for (int i = 0; i < k; i++) {
fin >> cows[i].first >> cows[i].second;
cows[i].first--, cows[i].second--;
cow_at_loc[cows[i].first][cows[i].second] = true;
}
int sum = 0;
for (int i = 0; i < k; i++) {
memset(visited, false, sizeof(visited));
c_cows_found = 0;
f_fill(cows[i].first, cows[i].second, -1, -1);
sum += k - c_cows_found;
}
fout << sum / 2 << endl;
return 0;
}