#include #include #include #include using namespace std; ifstream fin("regions.in"); ofstream fout("regions.out"); int a[128][128], b[128][128], c[128][128]; int n, r, k=0, t, br; bool fl; vector > v; void Init() { fin>>n>>r; for (int i=0; i<=n+1; i++) { a[0][i]=a[i][0]=a[n+1][i]=a[i][n+1]=-1; } for (int i=0; i<=n; i++) { for (int j=0; j<=n; j++) { b[i][j]=0; } } int x, y, z; for (int i=0; i>x>>y>>z; a[x][y]=z; } for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++) { c[i][j]=a[i][j]; } } } void Rec(int x, int y) { if (br==t) //finish { fl=true; return; } if (!(a[x][y]==0 or a[x][y]==t)) return; //not used or right br++; a[x][y]=-1; v.push_back(make_pair(x, y)); Rec(x, y-1); Rec(x-1, y); Rec(x, y+1); Rec(x+1, y); } void Printa() { for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++) { fout<0) { k++; v.resize(0); br=0; fl=false; t=a[i][j]; Rec(i, j); if (!fl) { k--; int length=v.size(); for (int l=0; l