Posts

Showing posts from March, 2016

UVA 11094 Solution- Continents

UVA 11094 Solution- Continents /* uva id: shoaib05 Accepted Time: 0.000 Algorithm: DFS */ #include<iostream> #include<string.h> #include<stack> using namespace std; char arr[25][25]; char ch,ch1; typedef pair<int,int> pii; pii pr; int m,n; int dfs(int x,int y) { pr=pii(x,y); stack<pii> st; st.push(pr); int count=0; arr[x][y]=ch1; while(!st.empty()) { pr=st.top(); st.pop(); x=pr.first; y=pr.second; count++; if(x>0 && arr[x-1][y]==ch) //Traverse to Up { pr=pii(x-1,y); st.push(pr); arr[x-1][y]=ch1; } if(x<m && arr[x+1][y]==ch) //Traverse to Down { pr=pii(x+1,y); st.push(pr); arr[x+1][y]=ch1; } if(y>0 && arr[x][y-1]==ch) //Traverse to Left { pr=pii(x,y-1); st.push(pr); arr[x][y-1]=ch1; } if(y<n && arr[x][y+1]==ch) //Traverse to Right { pr=pii(x,y+1); st.push(pr); arr[x][y+1]=ch1; }...