Language: C++

#include <iostream>
#include <cmath>
#include <set>
#include <memory>
using namespace std;

const int size = 101;
const double eps = 1e-9;

struct Vector2D {
    int x;
    int y;
    Vector2D(): x(0), y(0) {}
    Vector2D( int x, int y ): x(x), y(y) {}
    Vector2D operator -( Vector2D& right ) {
        return Vector2D( x-right.x, y-right.y );
    }
    bool operator ==( Vector2D& right ) {
        return x == right.x && y == right.y;
    }
};
typedef Vector2D* PVector2D;

// ツ四ツ角ツ形ツデツーツタ
int Q[size][8];
int QC;
void initQ() {
    QC = 0;
}
void inputQ() {
    for ( int i = 0; i < 8; i++ ) {
        cin >> Q[QC][i];
    }
    QC++;
}

// disjoint sets
int F[size];
int FC;
void initF() {
    FC = 0;
}
int get( int ind ) {
    return F[ind] == -1 ? ind : get( F[ind] );
}
bool same( int a, int b ) {
    int fa = get( a );
    int fb = get( b );
    return fa == fb;
}
void merge( int a, int b ) {
    int fa = get( a );
    int fb = get( b );
    if ( fa != fb ) {
        F[fb] = fa;
    }
}

//
PVector2D getTriangleA( int a ) {
    PVector2D answer = new Vector2D[3];
    answer[0] = Vector2D( Q[a][0], Q[a][1] );
    answer[1] = Vector2D( Q[a][2], Q[a][3] );
    answer[2] = Vector2D( Q[a][6], Q[a][7] );
    return answer;
}

PVector2D getTriangleB( int a ) {
    PVector2D answer = new Vector2D[3];
    answer[0] = Vector2D( Q[a][2], Q[a][3] );
    answer[1] = Vector2D( Q[a][4], Q[a][5] );
    answer[2] = Vector2D( Q[a][6], Q[a][7] );
    return answer;
}

int cross( Vector2D a, Vector2D b ) {
    return a.x*b.y - a.y*b.x;
}

int getM( Vector2D a ) {
    return abs(a.x) + abs(a.y);
}

bool collision( PVector2D t, Vector2D p ) {
    for ( int i = 0; i < 3; i++ ) {
        int ii = i;
        int kk = (i+2)%3;
        int c = cross( t[ii]-t[kk], p-t[kk] );
        if ( c == 0 && getM( p-t[kk] ) <= getM( t[ii]-t[kk] ) ) {
            return true;
        }
    }
    for ( int i = 0; i < 3; i++ ) {
        int ii = i;
        int jj = (i+1)%3;
        int kk = (i+2)%3;
        int c1 = cross( t[ii]-t[kk], p-t[kk] );
        int c2 = cross( t[jj]-t[kk], p-t[kk] );
        if ( c1 > 0 && c2 > 0 || c1 < 0 && c2 < 0 ) return false;
    }
    return true;
}

bool collision( int a, int b ) {
    PVector2D ta = getTriangleA( a );
    PVector2D tb = getTriangleB( b );

    for ( int i = 0; i < 3; i++ ) {
        if ( collision( ta, tb[i] ) ) return true;
        if ( collision( tb, ta[i] ) ) return true;
    }
    for ( int i = 0; i < 3; i++ ) {
        for ( int j = 0; j < 3; j++ ) {
            if ( ta[i] == tb[j] ) return true;
        }
    }

    return false;
}

int main() {
    int n;
    while ( cin >> n && n ) {

        for ( int i = 0; i < n; i++ ) {
            initF();
            initQ();

            int m;
            cin >> m;
            int color;
            for ( int j = 0; j < m; j++ ) {
                inputQ();
                F[FC++] = -1;
            }

            for ( int ii = 0; ii < m; ii++ ) {
                for ( int jj = 0; jj < m; jj++ ) {
                    if ( same( ii, jj ) ) continue;
                    if ( collision( ii, jj ) ) merge( ii, jj );
                }
            }

            set <int> S;
            for ( int j = 0; j < m; j++ ) {
                S.insert( get(j) );
            }

            cout << S.size() << endl;
        }
    }
    return 0;
}

Compiler output:
a.cc:25:7: error: reference to 'size' is ambiguous
   25 | int Q[size][8];
      |       ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:7:11: note:                 'const int size'
    7 | const int size = 101;
      |           ^~~~
a.cc: In function 'void inputQ()':
a.cc:32:16: error: 'Q' was not declared in this scope
   32 |         cin >> Q[QC][i];
      |                ^
a.cc: At global scope:
a.cc:38:7: error: reference to 'size' is ambiguous
   38 | int F[size];
      |       ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:7:11: note:                 'const int size'
    7 | const int size = 101;
      |           ^~~~
a.cc: In function 'int get(int)':
a.cc:44:12: error: 'F' was not declared in this scope; did you mean 'FC'?
   44 |     return F[ind] == -1 ? ind : get( F[ind] );
      |            ^
      |            FC
a.cc: In function 'void merge(int, int)':
a.cc:55:9: error: 'F' was not declared in this scope
   55 |         F[fb] = fa;
      |         ^
a.cc: In function 'Vector2D* getTriangleA(int)':
a.cc:62:27: error: 'Q' was not declared in this scope
   62 |     answer[0] = Vector2D( Q[a][0], Q[a][1] );
      |                           ^
a.cc: In function 'Vector2D* getTriangleB(int)':
a.cc:70:27: error: 'Q' was not declared in this scope
   70 |     answer[0] = Vector2D( Q[a][2], Q[a][3] );
      |                           ^
a.cc: In function 'int main()':
a.cc:134:17: error: 'F' was not declared in this scope
  134 |                 F[FC++] = -1;
      |                 ^