#include template class List { struct node { T data; node *next,*prev; } *f,*c; public: int n,pos; List() {n=pos=0;} ~List() {while(n) canc(); } T &cur() { return c->data; } T &operator[](int i) {go(i); return cur(); } T operator[](int i) const { node *p=f; while(i-->0) p=p->next; return p->data; } void add(const T &t) { c=f; pos=n; ins(t); } void ins(const T &t) { node *w,*p; if(n) { w=c; p=c->prev; c=p->next=w->prev=new node; if(!pos) f=c; } else p=w=f=c=new node; c->prev=p; c->next=w; c->data=t; n++; } T canc() { node *w=c,*p=c->prev; T ret=c->data; c=p->next=w->next; c->prev=p; delete w; if(!pos) f=c; n--; return ret; } void next() { c=c->next; if(++pos==n) pos=0; } void prev() { c=c->prev; if(--pos<0) pos=n-1; } void go(int d) { skip(d-pos); } void skip(int d) { int dir=1; if(d<0) { d=-d; dir=0; } d%=n; if(d>n/2) {d=n-d; dir= !dir; } while(d--) dir?next():prev(); } List &operator=(const List &a) { if(n) go(0); while(n) canc(); for(int i=0;i class Graph { public: struct arc { int node; A data; P peso; }; struct node { T data; List in,out; } nodes[nmax]; int n; Graph() {n=0;} void add_node(const T &t){ nodes[n++].data=t; } void add_arc_or(int s, int d, P p, A info) { arc a; a.data=info; a.peso=p; a.node=d; nodes[s].out.add(a); a.node=s; nodes[d].in.add(a); } void add_arc_sym(int s,int d, P p, A i) { add_arc_or(s,d,p,i); if(s!=d) add_arc_or(d,s,p,i); } node &operator[](int i) { return nodes[i]; } List shortest_path(int first, int last, P &p) { P pr[nmax]; List q,ret; int i,k,nod,bin[nmax],pred[nmax]; for(i=0; ip+a.peso || bin[k]) pr[k]=p+a.peso, pred[k]=nod; if(bin[k]) q.ins(k); bin[k]=0; } } p=-1; return ret; } }; #include #include char nomi[100][25],s[25],c; int addr[100],addgr[25],pr[100][1000],ttl[100][1000],totp[100]; int pid,t,i,j,k,ga,m,na,n,numg[25],gruppo[25][100],totgruppi; int nn,nrouter,caso=0,numlinee,a,sorg,peso,h,totnodi; FILE *fp=fopen("mbone.in","r"); int cercar() { int i; for(i=0;i g; inizia(); printf("Network #%d\n",++caso); for(i=0;i0) { for(i=0;ipr[k][j]) { h=pr[k][i]; pr[k][i]=pr[k][j]; pr[k][j]=h; h=ttl[k][i]; ttl[k][i]=ttl[k][j]; ttl[k][j]=h; } } } for(i=0;iaddr[j]) { h=addr[i]; addr[i]=addr[j]; addr[j]=h; h=totp[i]; totp[i]=totp[j]; totp[j]=h; for(k=0;k<1000;k++) { h=pr[i][k]; pr[i][k]=pr[j][k]; pr[j][k]=h; h=ttl[i][k]; ttl[i][k]=ttl[j][k]; ttl[j][k]=h; } } for(k=0;k0) for(i=0;i