Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- using namespace std;
- typedef long long ll;
- const int maxn = 5000;
- vector<int> graph[maxn];
- int main() {
- int n, m;
- cin >> n >> m;
- char c[n][m];
- int mat[n][m];
- int idx = 0;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- cin >> c[i][j];
- mat[i][j] = idx;
- idx++;
- }
- }
- int di[] = {-1, 1, 0, 0};
- int dj[] = {0, 0, -1, 1};
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- for(int k = 0; k < 4; k++) {
- int ti = i + di[k];
- int tj = j + dj[k];
- if(ti >= 0 and ti < n and tj >= 0 and tj < m and c[i][j] == c[ti][tj]) {
- graph[mat[i][j]].push_back(mat[ti][tj]);
- graph[mat[ti][tj]].push_back(mat[i][j]);
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement