/******************************************* Problem - Princess Penelope Solution By - Sean Falconer *******************************************/ #include #include #include using namespace std; struct Pos { int r, c; Pos() {} Pos(int r, int c) : r(r), c(c) {} }; int map[5][20][20]; int visited[5][20][20]; int N, M; void addAdjacencies(Pos & p, queue & q, int & i) { if(p.r > 0 && p.c > 0 && map[i][p.r-1][p.c-1]) q.push(Pos(p.r-1, p.c-1)); if(p.r > 0 && map[i][p.r-1][p.c]) q.push(Pos(p.r-1, p.c)); if(p.r > 0 && p.c < M-1 && map[i][p.r-1][p.c+1]) q.push(Pos(p.r-1, p.c+1)); if(p.c > 0 && map[i][p.r][p.c-1]) q.push(Pos(p.r, p.c-1)); if(p.c < M-1 && map[i][p.r][p.c+1]) q.push(Pos(p.r, p.c+1)); if(p.r < M-1 && p.c > 0 && map[i][p.r+1][p.c-1]) q.push(Pos(p.r+1, p.c-1)); if(p.r < M-1 && map[i][p.r+1][p.c]) q.push(Pos(p.r+1, p.c)); if(p.r < M-1 && p.c < M-1 && map[i][p.r+1][p.c+1]) q.push(Pos(p.r+1, p.c+1)); } int main() { int C; cin >> C; for(int d = 0; d < C; d++) { int i, r, c, bestbid = 0, bestindex = 0; cin >> N >> M; for(i = 0; i < N; i++) { for(r = 0; r < M; r++) { for(c = 0; c < M; c++) { cin >> map[i][r][c]; visited[i][r][c] = 0; } } } for(i = 0; i < N; i++) { for(r = 0; r < M; r++) { for(c = 0; c < M; c++) if(!visited[i][r][c] && map[i][r][c]) { queue q; q.push(Pos(r, c)); int size = 0; while(!q.empty()) { Pos p = q.front(); q.pop(); if(!visited[i][p.r][p.c]) { visited[i][p.r][p.c] = 1; size++; addAdjacencies(p, q, i); } } if(size > bestbid) { bestbid = size; bestindex = i; } } } } cout << bestindex+1 << " " << bestbid << endl; } return 0; }