Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- vector<int> parent;
- int find(int x)
- {
- if (parent[x]==x) return x;
- return parent[x]=find(parent[x]);
- }
- void join(int x, int y)
- {
- parent[x]=find(y);
- }
- int main() {
- int r,c;
- cin>>r>>c;
- parent.resize(r*c);
- vector<string> map(r);
- for (int i = 0; i < r*c; ++i)
- {
- parent[i]=i;
- }
- for (int i = 0; i < r; ++i)
- {
- cin>>map[i];
- }
- for (int i = 0; i < r; ++i)
- {
- for (int j = 0; j < c; ++j)
- {
- if (j<c-1)
- {
- if (map[i][j]==map[i][j+1])
- {
- join(i*c+j, i*c+j+1);
- }
- }
- if (i<r-1)
- {
- if (map[i][j]==map[i+1][j])
- {
- join(i*c+j, (i+1)*c+j);
- }
- }
- }
- }
- int n;
- cin>>n;
- int r1,c1,r2,c2;
- for (int i = 0; i < n; ++i)
- {
- cin>>r1>>c1>>r2>>c2;
- r1--;
- c1--;
- r2--;
- c2--;
- if (find(r1*c+c1)==find(r2*c+c2))
- {
- if (map[r1][c1]=='0')
- {
- cout<<"binary"<<endl;
- }
- else cout<<"decimal"<<endl;
- }
- else cout<<"neither"<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement