Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
- int dy[] = {1, 1, 1, 0, 0, -1, -1, -1};
- bool isValid(int x, int y, int alto, int ancho)
- {
- return (0 <= x && x < alto && 0 <= y && y < ancho);
- }
- int cant;
- void floodfill(vector <string> &m, int x, int y)
- {
- cant++;
- m[x][y] = '0';
- for(int i=0; i<8; i++)
- {
- int a = x+dx[i];
- int b = y+dy[i];
- if(isValid(a, b, m.size(), m[0].size()) && m[a][b] == '1')
- {
- floodfill(m, a, b);
- }
- }
- }
- int main()
- {
- int tc;
- cin >> tc;
- string tmp;
- getline(cin, tmp);
- getline(cin, tmp);
- while(tc--)
- {
- vector <string> vec;
- getline(cin, tmp);
- while(tmp.size())
- {
- vec.push_back(tmp);
- getline(cin, tmp);
- }
- int maximo = 0;
- for(int i=0; i<vec.size(); i++)
- {
- for(int j=0; j<vec[i].size(); j++)
- {
- if(vec[i][j] == '1')
- {
- cant = 0;
- floodfill(vec, i, j);
- maximo = max(maximo, cant);
- }
- }
- }
- cout << maximo << endl;
- if(tc)
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement