Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <cstring>
- #include <cstdio>
- #include <cstdlib>
- #include <vector>
- #include <map>
- #include <stack>
- #include <bitset>
- #include <queue>
- #include <unordered_map>
- #include <set>
- #include <string>
- #include <sstream>
- #include <functional>
- #include <list>
- #include <fstream>
- #define cont continue
- #define int_max 0x3f3f3f3f
- #define byte_max 0x3f
- #define max_v 110
- #define pow_2(n) (1 << n)
- #define cin fin
- #define cout fout
- using namespace std;
- ifstream fin("countcross.in");
- ofstream fout("countcross.out");
- const int row[] = {0, 0, -1, 1};
- const int col[] = {1, -1, 0, 0};
- int graph[max_v][max_v], belong[max_v][max_v];
- bool cow[max_v][max_v], vis[max_v][max_v];
- int N, V, E;
- vector<int> regions;
- void add_edge(int a, int b, int c, int d){
- int x = c - a;
- int y = d - b;
- int ind;
- for(int i = 0; i<4; i++){
- if(row[i] == x && col[i] == y){
- ind = i;
- }
- }
- graph[a][b] |= pow_2(ind);
- }
- int dfs(int x, int y){
- if(x < 1 || y < 1 || x > N || y > N || vis[x][y]){ //one based index
- return 0;
- }
- vis[x][y] = true;
- belong[x][y] = regions.size();
- int total = (cow[x][y]) ? 1:0;
- for(int i = 0; i<4; i++){
- if((graph[x][y]&pow_2(i)) == 0){
- total += dfs(x + row[i], y + col[i]);
- }
- }
- return total;
- }
- int main() {
- cin >> N >> V >> E;
- for(int i = 0; i<E; i++){
- int a, b, c, d;
- cin >> a >> b >> c >> d;
- add_edge(a, b, c, d);
- add_edge(c, d, a, b);
- }
- for(int i = 0; i<V; i++){
- int a, b;
- cin >> a >> b;
- cow[a][b] = true;
- }
- for(int i = 1; i<=N; i++){
- for(int j = 1; j<=N; j++){
- if(!vis[i][j]){
- regions.push_back(dfs(i, j));
- }
- }
- }
- int total = 0, used = V;
- for(int i = 0; i<regions.size(); i++){
- total += regions[i] * (used - regions[i]);
- used -= regions[i];
- }
- cout << total;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement