#include #include #include using namespace std; ifstream fin("regions.in"); ofstream fout("regions.out"); struct flag { int x,y,c; }; int n,r,maxI,maxC,table[105][105]; flag f[1605]; void in() { fin>>n>>r; for (int i=0; i>f[i].x>>f[i].y>>f[i].c; table[f[i].x][f[i].y]=-1; if (f[i].c>maxC) { maxC=f[i].c; maxI=i; } } } void bfs (flag z) { int br=1; queue > q; q.push(make_pair(z.x,z.y)); table[z.x][z.y]=1; while (!q.empty()) { int x,y; x=q.front().first; y=q.front().second; q.pop(); // table[x][y]=1; // br++; if (br==z.c) break; if (x!=1 && table[x-1][y]==0) { q.push(make_pair(x-1,y)); table[x-1][y]=1; br++; if (br==z.c) return; } if (x!=n && table[x+1][y]==0) { q.push(make_pair(x+1,y)); table[x+1][y]=1; br++; if (br==z.c) return; } if (y!=1 && table[x][y-1]==0) { q.push(make_pair(x,y-1)); table[x][y-1]=1; br++; if (br==z.c) return; } if (y!=n && table[x][y+1]==0) { q.push(make_pair(x,y+1)); table[x][y+1]=1; br++; if (br==z.c) return; } } } void solve () { bfs(f[maxI]); } void print() { for (int i=1; i<=n; i++) { for (int j=1; j