I used bit operation to represent the states of the switches state of the villa. #include <iostream> #include <cstdio> #include <vector> #include <queue> #include <sstream> #include <string> #include <cstring> #include <cmath> using namespace std; struct Point{ int x,y; }; int kase=1; Point points[11500]; int arr[11][1024]; int array_map_par[11500]; bool door[15][15]; bool light_swtch[15][15]; bool flag; int RR,DD,SS;
Category: Graph Algorithm
314
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <string> #define NORTH 0 #define EAST 1 #define SOUTH 2 #define WEST 3 using namespace std; struct State{ int x,y,dir; int val; }; int r,c; int gr[55][55][4]; string face; int bx,by,ex,ey; void bfs() { int dir; queue<int> q; if(face=="south") dir=SOUTH; else if(face=="north") dir=NORTH; else if(face=="east") dir=EAST;
298
#include <iostream> #include <cstdio> #include <queue> #include <sstream> #include <string> #include <cstring> #include <cmath> using namespace std; bool gr[30][30][7][7]; //bool gr2D[30][30]; struct Point{ int x,y,velocity,accleration; int val; }; Point St,Fn; int m,n; void bfs() { int x,y,v,a,val; int dx,dy,tx,ty; queue<int> q; q.push(St.x);q.push(St.y); q.push(0);q.push(0);q.push(0); gr[St.x][St.y][0+3][0+3]=1; while(!q.empty()) { x=q.front();q.pop(); y=q.front();q.pop(); v=q.front();q.pop(); a=q.front();q.pop(); val = q.front();q.pop(); //cout<<x<<" "<<y<<"
1208
#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <string> #include <sstream> #include <algorithm> using namespace std; struct Edge{ int source,destination,weight; }; //to keep track of parent and rank of union find struct subset{ int parent; int rank; }; bool graph[100][100]; vector<Edge> edges; subset* subsets; bool cmp(Edge a,Edge b) { return a.weight<b.weight; } int find(int
10048
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #define INF 1000000 using namespace std; int gr[105][105]; int _mn(int a,int b) { if(a>b) return b; return a; } int _mx(int a,int b) { if(a>b) return a; return b; } int main() { bool f=0; int kase=1; int C,S,Q; int a,b,d; while(cin>>C) { cin>>S>>Q; if(C+S+Q==0) break; for(int
10067
#include <iostream> #include <queue> using namespace std; bool visit[10][10][10][10]; int arr[3]={0,1,-1}; struct states{ int a,b,c,d; int step; }; int main() { int t,n,stp; states tmp; int tw,tx,ty,tz; int a,b,c,d,x,y,w,z; cin>>t; while(t–) { states src,trgt,tmp; for(int i=0;i<10;i++) for(int j=0;j<10;j++) for(int k=0;k<10;k++) for(int l=0;l<10;l++) visit[i][j][k][l]=0; cin>>a>>b>>c>>d; src.a=a; src.b=b; src.c=c; src.d=d; src.step=0; cin>>a>>b>>c>>d; trgt.a=a; trgt.b=b; trgt.c=c; trgt.d=d; trgt.step=-1;
10047
#include <iostream> #include <queue> #define Green 0 #define Black 1 #define Red 2 #define Blue 3 #define White 4 #define N 0 #define W 1 #define S 2 #define E 3 using namespace std; struct states{ int ro,col,wt,direction,wheelcolr; }; int m,n,ans; bool bfs(states src,states trgt,char gr[30][30]) { int r,c,d,colr,weight; states tmp; queue<states> q; q.push(src); bool
10199
#include <iostream> #include <cstdio> #include <vector> #include <sstream> #include <string> #include <algorithm> #include <queue> #include <cstring> #include <map> #include <set> using namespace std; map<string,int> mp; map<int,string> mp2; vector<int> gr[105]; //vector<int> V; bool visit[105]; bool ap[105]; int discTime[105]; int low[105]; int par[105]; int cnt; set<string> SET; void cutvertex(int u) { static int dsc_time=0; low[u]=discTime[u]=dsc_time++; visit[u]=1; int
315
A vertex in an undirected connected graph is an articulation point (or cut vertex) iff removing it (and edges through it) disconnects the graph. Articulation points represent vulnerabilities in a connected network – single points whose failure would split the network into 2 or more disconnected components. They are useful for designing reliable networks. For
872
#include <iostream> #include <string> #include <sstream> #include <fstream> #include <queue> #include <algorithm> #include <cstring> #include <set> using namespace std; int noOfelement; int mp[26]; string str,str1,str2; string output[2000]; int kk; bool gr[27][27]; stringstream ss; int elements[26]; set<string> SET; //ofstream out; bool check(int elemnt,bool visit[]) { for(int i=0;i<26;i++) { if(gr[i][elemnt] && mp[i]!=-1 && visit[mp[i]]==0) return 0; }