Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我这为啥超时 高手看看#include<iostream> using namespace std; int re2[100]; int c[100]; int re[100]; int b,max; int m,n,l; struct list { int i; list * next; }; list * h[100],*t[100]; inline void add(int x,int y) { list *p; if(h[x]==NULL) { p=new list; p->i=y; p->next=NULL; h[x]=p; t[x]=p; } else { p=new list; p->i=y; p->next=NULL; t[x]->next=p; t[x]=p; } } void search(int x) { if(x>n) { if(b>max) { max=b; int j=0; for(j=0;j<b;j++) re2[j]=re[j]; } return ; } if(c[x]!=0)search(x+1); else { c[x]=1;re[b++]=x; list *p=h[x]; while(p!=NULL) { c[p->i]=2; p=p->next; } search(x+1); p=h[x]; while(p!=NULL) { c[p->i]=0; p=p->next; } b--;c[x]=2; search(x+1); c[x]=0; } } int main() { cin>>m; while(m--) { int i; b=0;max=0; cin>>n>>l; //init for(i=1;i<=n;i++) h[i]=NULL; for(i=1;i<=n;i++) c[i]=0; int x,y; for(i=0;i<l;i++) { cin>>x>>y; if(x<y) add(x,y); else add(y,x); } ///////////////// search(1); cout<<max<<endl; for(i=0;i<max;i++) cout<<re2[i]<<" "; cout<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator