// // File: regulate.cc // Author: cteam21 // // Created on November 13, 2011, 2:58 PM // #include #include #include #define INDEX (start%8001) // // // struct elem { int val; elem * next; }; struct base{ elem * f; elem * l; }; base * spojak; char ** graph; bool monopole(int node, int company){ elem * ptr=spojak[node].f; int cnt=0; while (ptr){ if (graph [ptr->val][node]==company){ cnt++; if (cnt==2)return true; } ptr=ptr->next; } return false; } bool redundancy(int a, int b, int c){ bool * disc = new bool[8001]; memset(disc, false, 8001); int * queue= new int[8001]; int start=0, length=1; int temp; elem * temp2; queue[0]=a; while (length>0){ temp=queue[INDEX]; start=(start+1)%8001; length--; disc[temp]=true; temp2=spojak[temp].f; while (temp2){ if (graph[temp][temp2->val]==c){ if (temp2->val==b) { delete[]disc; delete[]queue; return true; } if (disc[temp2->val]!=true){ queue[INDEX]=temp2->val; length++; } } temp2=temp2->next; } } delete[]disc; delete[]queue; return false; } int main(int argc, char** argv) { int servers, cables, comps, trans; int a, b, c; spojak=new base [8001]; graph=new char * [8001]; for (int i=0 ; i<8001; i++){ graph[i]=new char [8001]; memset(graph[i], 0, 8001); } memset(spojak, NULL, 8001*sizeof(base)); while (42){ scanf("%d%d%d%d", &servers, &cables, &comps, &trans); if (servers==0&&cables==0&&comps==0&&trans==0){ //leaks return 0; } for (int i=0; ival=b; help->next=NULL; if (spojak[a].l==NULL)spojak[a].f=spojak[a].l=help; else { spojak[a].l->next=help; spojak[a].l=help; } help = new elem; help->val=a; help->next=NULL; if (spojak[b].l==NULL)spojak[b].f=spojak[b].l=help; else { spojak[b].l->next=help; spojak[b].l=help; } } for (int i=0; i