Language: C++

#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//v.erase(unique(v.begin(),v.end()),v.end());
 
#define ff first
#define ss second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
 
 
typedef long double ld;
typedef long long ll;
const int N = 3550;
const ll mod = 998244353;
const int INF = 1e+9;
using namespace std;
//using namespace __gnu_pbds;
 
//typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

 
map <int, int> l, r;
int d_l[N], d_r[N];
vector <int> la, ra;
vector <pair <int, pair <int, int>>> X, Y;
bool adj_l[N][N], adj_r[N][N], vis[N][N];
int curr1 = 1, curr2 = 1;
ll ans = 0;
bool wea = false;
 
 
void llenar(){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            adj_l[i][j] = true;
            adj_r[i][j] = true;
        }
    }
    
}
 
void dfs(int x, int y){
    vis[x][y] = true;
    if(wea or (x <= 0) or (x >= (curr1 - 1)) or (y <= 0) or (y >= (curr2 - 1))) {wea = true; return;} 
    vis[x][y] = true;
    ans += d_l[x] * d_r[y];
    //ahora visitamos llos cuatro lados
 
	if(adj_r[y][x] and !vis[x][y - 1]) dfs(x, y - 1); 
    if(wea) return;
	if(adj_r[y + 1][x] and !vis[x][y + 1]) dfs(x, y + 1); 
    if(wea) return;
	if(adj_l[x][y] and !vis[x - 1][y]) dfs(x - 1, y); 
    if(wea) return;
	if(adj_l[x + 1][y] and !vis[x + 1][y]) dfs(x + 1, y); 
  	if(wea) return;
}
 
void solve(){
    int n, m; cin >> n >> m;
    la.push_back(0);
    ra.push_back(0);
    for(int i = 0; i < n; i++){
        int a, b, c; cin >> a >> b >> c;
        X.push_back({c, {a, b}});
        ra.push_back(c);
        la.push_back(a); la.push_back(b);
    }
    for(int i = 0; i < m; i++){
        int d, e, f; cin >> d >> e >> f;
        Y.push_back({d, {e, f}});
        ra.push_back(e); ra.push_back(f);
        la.push_back(d);
    }
    
    sort(la.begin(), la.end());
    sort(ra.begin(), ra.end());
    la.erase(unique(la.begin(),la.end()),la.end());
    ra.erase(unique(ra.begin(),ra.end()),ra.end());
    //for(auto x: ra) trace(x);
    if((la.size() <= 2) or (ra.size() <= 2)){
        cout << "INF" << endl;
        return;
    }
    for(auto val: la) l[val] = curr1++;
    for(int i = 0; i < la.size() - 1; i++){
        d_l[i + 1] = la[i + 1] - la[i];
    }
 
    for(auto val: ra) r[val] = curr2++;
    for(int i = 0; i < ra.size() - 1; i++){
        d_r[i + 1] = ra[i + 1] - ra[i];
    }
    //trace(curr1, curr2);
    //for(int i = 0; i < 12; i++) trace(d_r[i]);
    //ya ahora tenemos mapeado todos las weadas
    
    llenar();
    
    //ahora recorremos de nuevo la mrd
    
    for(int i = 0; i < n; i++){
        int a = X[i].ss.ff, b = X[i].ss.ss, c = X[i].ff;
        for(int j = l[a]; j < l[b]; j++) adj_r[r[c]][j] = false; 
    }
    for(int i = 0; i < m; i++){
        int d = Y[i].ff, e = Y[i].ss.ff, f = Y[i].ss.ss;
        for(int j = r[e]; j < r[f]; j++) adj_l[l[d]][j] = false; 
    }
    /*
    for(int i = 0; i < 12; i++){
        for(int j = 0; j < 12; j++){
            if(adj_r[i][j]) cout << ".";
            else cout << "#";
        }
        cout << endl;
    }*/
    //ya llenamos los vacios de mrd que no se pueden cruzar xd
    
    //ahora el dfs
    dfs(l[0], r[0]);
    
    if(wea){
        cout << "INF" << endl;
        return;
    }
    cout << ans << endl;
}
 
int main(){
    fastio;
    int tc = 1; 
    //cin >> tc;
    
    while(tc--) solve();
    
    return 0;
}

Compiler output:
a.cc:20:1: error: 'map' does not name a type
   20 | map <int, int> l, r;
      | ^~~
a.cc:22:1: error: 'vector' does not name a type
   22 | vector <int> la, ra;
      | ^~~~~~
a.cc:23:1: error: 'vector' does not name a type
   23 | vector <pair <int, pair <int, int>>> X, Y;
      | ^~~~~~
a.cc: In function 'void solve()':
a.cc:58:15: error: 'cin' was not declared in this scope
   58 |     int n, m; cin >> n >> m;
      |               ^~~
a.cc:2:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    1 | #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
  +++ |+#include <iostream>
    2 | //v.erase(unique(v.begin(),v.end()),v.end());
a.cc:59:5: error: 'la' was not declared in this scope; did you mean 'll'?
   59 |     la.push_back(0);
      |     ^~
      |     ll
a.cc:60:5: error: 'ra' was not declared in this scope
   60 |     ra.push_back(0);
      |     ^~
a.cc:63:9: error: 'X' was not declared in this scope
   63 |         X.push_back({c, {a, b}});
      |         ^
a.cc:69:9: error: 'Y' was not declared in this scope
   69 |         Y.push_back({d, {e, f}});
      |         ^
a.cc:80:9: error: 'cout' was not declared in this scope
   80 |         cout << "INF" << endl;
      |         ^~~~
a.cc:80:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:80:26: error: 'endl' was not declared in this scope
   80 |         cout << "INF" << endl;
      |                          ^~~~
a.cc:2:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    1 | #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
  +++ |+#include <ostream>
    2 | //v.erase(unique(v.begin(),v.end()),v.end());
a.cc:83:23: error: 'l' was not declared in this scope
   83 |     for(auto val: la) l[val] = curr1++;
      |                       ^
a.cc:88:23: error: 'r' was not declared in this scope
   88 |     for(auto val: ra) r[val] = curr2++;
      |                       ^
a.cc:101:17: error: 'X' was not declared in this scope
  101 |         int a = X[i].ss.ff, b = X[i].ss.ss, c = X[i].ff;
      |                 ^
a.cc:102:21: error: 'l' was not declared in this scope
  102 |         for(int j = l[a]; j < l[b]; j++) adj_r[r[c]][j] = false;
      |                     ^
a.cc:102:33: error: 'b' was not declared in this scope
  102 |         for(int j = l[a]; j < l[b]; j++) adj_r[r[c]][j] = false;
      |                                 ^
a.cc:102:48: error: 'r' was not declared in this scope
  102 |         for(int j = l[a]; j < l[b]; j++) adj_r[r[c]][j] = false;
      |                                                ^
a.cc:102:50: error: 'c' was not declared in this scope
  102 |         for(int j = l[a]; j < l[b]; j++) adj_r[r[c]][j] = false;
      |                                                  ^
a.cc:105:17: error: 'Y' was not declared in this scope
  105 |         int d = Y[i].ff, e = Y[i].ss.ff, f = Y[i].ss.ss;
      |                 ^
a.cc:106:21: error: 'r' was not declared in this scope
  106 |         for(int j = r[e]; j < r[f]; j++) adj_l[l[d]][j] = false;
      |                     ^
a.cc:106:23: error: 'e' was not declared in this scope
  106 |         for(int j = r[e]; j < r[f]; j++) adj_l[l[d]][j] = false;
      |                       ^
a.cc:106:33: error: 'f' was not declared in this scope
  106 |         for(int j = r[e]; j < r[f]; j++) adj_l[l[d]][j] = false;
      |                                 ^
a.cc:106:48: error: 'l' was not declared in this scope
  106 |         for(int j = r[e]; j < r[f]; j++) adj_l[l[d]][j] = false;
      |                                                ^
a.cc:119:9: error: 'l' was not declared in this scope
  119 |     dfs(l[0], r[0]);
      |         ^
a.cc:119:15: error: 'r' was not declared in this scope
  119 |     dfs(l[0], r[0]);
      |               ^
a.cc:122:9: error: 'cout' was not declared in this scope
  122 |         cout << "INF" << endl;
      |         ^~~~
a.cc:122:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:122:26: error: 'endl' was not declared in this scope
  122 |         cout << "INF" << endl;
      |                          ^~~~
a.cc:122:26: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:125:5: error: 'cout' was not declared in this scope
  125 |     cout << ans << endl;
      |     ^~~~
a.cc:125:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:125:20: error: 'endl' was not declared in this scope
  125 |     cout << ans << endl;
      |                    ^~~~
a.cc:125:20: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc: In function 'int main()':
a.cc:6:49: error: 'cin' was not declared in this scope
    6 | #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
      |                                                 ^~~
a.cc:129:5: note: in expansion of macro 'fastio'
  129 |     fastio;
      |     ^~~~~~
a.cc:6:49: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    6 | #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
      |                                                 ^~~
a.cc:129:5: note: in expansion of macro 'fastio'
  129 |     fastio;
      |     ^~~~~~